Jump to content

Archived

This topic is now archived and is closed to further replies.

daedalus

Need Help with join

Recommended Posts

Hey,

Ok I have two tables, one storing fanart information another storing reviews. Now each of these has similar fields (Author, Title, ID etc) but also some different fields, i.e. the fanart has a URL field, the review has a content field.

Both also have a column storing the date they were added to the database. Ok, what I want to get is the 5 most recent additions to the database. Now generating a list based on one type is easily done, with a basic select statement, and ordered by date.

However joining the two tables, so I can see the most recently added based on both tables, is proving more tricky, and wondered if anyone could help.

I considered maybe using a union statement, but I couldn't get that to work. So I'm guessing I need a join. Anyhelp would be appriciated.

Thanks

Share this post


Link to post
Share on other sites
The UNION statement should work just fine -- just make sure you explicity request only the "like" columns:

[code]( SELECT col1, col2, dateCol FROM t1 )
UNION ALL
( SELECT col1, col2, dateCol FROM t2 )
ORDER BY dateCol DESC LIMIT 5[/code]

Hope that helps.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.