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? Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Jabop Posted June 12, 2008 Author Share Posted June 12, 2008 ^^ Fail Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.