2 tables query - ordering

Hi, Im not sure if this is something that can be done in 1 query or not.

In leymens terms this is what I have.

2 database tables:

users
-user_id
-user_name

and

Images
-user_id
-image_id
-image_name
-image_datePosted

now what I want to do is to grab all users and order them by who posted an image last.

is that something I can do?

Thanks :slight_smile:

Mike

[edit - just realised this should be in the mysql forum - sorry :frowning: )

Thread moved to MySQL forum. For future reference if a thread is in the wrong forum, just click on the flag icon and in the report state which forum the thread belongs in.


select users.user_name,
       max(images.image_datePosted) as lastPost
  from users
  join images
    on users.user_id = images.user_id
 group by users.user_id
 order by lastPost desc

Thanks SwampBoogie (and apologies SpacePhoenix)

Just to take this a step further, could i add in a where statement to only count the images that are not in the future.

sort of like where image_dateposted is not in the future.

Thanks, :slight_smile:


select users.user_name,
       max(images.image_datePosted) as lastPost
  from users
  join images
    on users.user_id = images.user_id
 where images.image_dateposted <= current_date
  group by users.user_id
 order by lastPost desc