Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.