daedalus Posted March 15, 2006 Share Posted March 15, 2006 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 https://forums.phpfreaks.com/topic/5034-need-help-with-join/ Share on other sites More sharing options...
fenway Posted March 15, 2006 Share Posted March 15, 2006 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 https://forums.phpfreaks.com/topic/5034-need-help-with-join/#findComment-17877 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.