mysql - SQL Latest photos from contacts (grouped by contact) -


The short version of this question is that I want to achieve anything with the things seen on Flickr's homepage

Here's a long explanation: For example, I have 3 friends: John, George and Andrea. The list that I want to remove should look like this:

George

  • Photos - 2010-05-18
  • Photos - 2010-05- 18
  • Photo - 2010-05-12

John

  • Photo - 2010-05-17
  • Photo - 2010-05-14
  • Photo - 2010-05-12

Andrea

  • Photo - 2010-05- 15
  • Photos - 2010-05-15
  • Photos - 2010-05-15

Friends with the latest photo uploaded on top But follow his or her 2 next file.

I want to do this from MySQL, and for that time when I came here:

  select photos.user_id, photos id, photos.date_uploaded photo WHERE photos .user_id IN (user_relations select user2_id WHERE user1_id = 8) ORDER date_uploaded DESC  

Where user1_id = 8 is currently logged in user and User2_id are the friends ID. This query actually returns the latest files uploaded with date = 8 sorted IDs by the user's contacts. However, I want to limit the grouping above and limit.

Hope this makes sense. Thank you in advance.

Sometimes, the only way to build a piece of SEL is so ugly and hey, that The choice of many questions becomes attractive: -)

I just ask a question to get a list of my friends, for each friend, get three most recent photos like something:

friend_list = sqlexec "relationship where user1_id =" + current_user_id photolist = [] friend_list for friends: photolist + sqlexec "user_i Select d, upload date from the photo, "+" where user_id = "+ friend.get (" user2_id ") +" order only get 3 rows of command by date_uploaded "# Do something with the folist now

You are not limited to a regular expression for matching a disgusting pattern to any of it as a query; it is "smart" "It would be nice to be, but it is rarely necessary I prefer practical perspectives I do.


Comments