Jabop Posted June 12, 2008 Share Posted June 12, 2008 I have two tables: Table A ID | Name | Date | Type Table B ID | Name | Date | Type Each of these tables have identical table structure. What I am trying to achieve is selecting 10 records TOTAL, from BOTH of the tables, ordering by Date DESC. What is the best method to go about this? Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/ Share on other sites More sharing options...
zenag Posted June 12, 2008 Share Posted June 12, 2008 SELECT * FROM table1, table2 ORDER by date desc Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/#findComment-563651 Share on other sites More sharing options...
Jabop Posted June 12, 2008 Author Share Posted June 12, 2008 ^^ Fail Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/#findComment-563671 Share on other sites More sharing options...
zenag Posted June 12, 2008 Share Posted June 12, 2008 (SELECT * FROM table1) UNION (SELECT * FROM table2) ORDER by date desc Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/#findComment-563749 Share on other sites More sharing options...
fenway Posted June 12, 2008 Share Posted June 12, 2008 Sure.. but that doesn't limit to 10. Do you care where the 10 are from? Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/#findComment-564097 Share on other sites More sharing options...
Jabop Posted June 12, 2008 Author Share Posted June 12, 2008 Zanag, that worked. Thank you! I need to do some research on UNION, because it is new to me. Sure.. but that doesn't limit to 10. Do you care where the 10 are from? No, any result can be from either table - I just want the most recent 10 to display. Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/#findComment-564234 Share on other sites More sharing options...
fenway Posted June 13, 2008 Share Posted June 13, 2008 Then: ( (SELECT * FROM table1) UNION (SELECT * FROM table2) ) ORDER by date desc LIMIT 10 Link to comment https://forums.phpfreaks.com/topic/109832-selecting-from-two-tables-displaying-both-results/#findComment-564759 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.