jonniejoejonson Posted January 21, 2009 Share Posted January 21, 2009 How do I pull out the 10 most recent records from a group of tables. eg. table1-images table2-videos tables4-sounds table3-comments each table has a userId column and a column for the date and time that it was created. If i wanted to select the 10 most recent from all of the tables how would i do this? regards to any responders. Link to comment https://forums.phpfreaks.com/topic/141708-multiple-tables-problem/ Share on other sites More sharing options...
corbin Posted January 21, 2009 Share Posted January 21, 2009 For 1 table: SELECT * FROM sometable ORDER BY datecolumn DESC LIMIT 10; (Really you could just order by the primary key DESC.) I don't think it would be reasonably possible to do it from 4 tables in 1 query. You could probably do some subqueries or some huge joins or something to get it all in 1 query, but it wouldn't be pretty. Link to comment https://forums.phpfreaks.com/topic/141708-multiple-tables-problem/#findComment-741862 Share on other sites More sharing options...
jonniejoejonson Posted January 21, 2009 Author Share Posted January 21, 2009 Thanks Corbin, Im trying to create a recent activities list like on facebook. However this would require that I either somehow join all the tables and select the first 10 most recent activities and then the 10-20 most recent activities of this combined table or would you suggest that i have a seperate recenet activities table, that has every action that every user makes, and then pull the data from there? regards J. Link to comment https://forums.phpfreaks.com/topic/141708-multiple-tables-problem/#findComment-741872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.