Jump to content


Need Help with join

  • Please log in to reply
1 reply to this topic

#1 daedalus

  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 15 March 2006 - 12:59 PM


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.


#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 March 2006 - 05:38 PM

The UNION statement should work just fine -- just make sure you explicity request only the "like" columns:

( SELECT col1, col2, dateCol FROM t1 ) 
( SELECT col1, col2, dateCol FROM t2 ) 

Hope that helps.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users