Jump to content

Need Help with join


daedalus

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
Link to comment
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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.