Jump to content

multiple tables problem


jonniejoejonson

Recommended Posts

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

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.