I have these tables:
Users, A table contains the users:
+--------------------------
| ID | Name |
+--------------------------
Dogs, A table contains the dogs (Last change is a time stamp telling when this dog status last changed):
+---------------------------------------------------------
| ID | Name | Last_Changed_At |
+---------------------------------------------------------
Users_Dogs_Relations, A table that describe which dog belong to which user, where multiple dogs can be belong to one user, multiple users can have the same dog, and multiple dogs can be belong to multiple users. (In short, any user can be related to any dog):
+------------------------------------
| UserID | DogID |
+------------------------------------
Users_Friend_Relation, A table describe which user is friend of which user:
+------------------------------------
| UserID1 | UserID2 |
+------------------------------------
What i want to do is to tell Steve (one of the users), all the name of the dogs that his friends have (ordered by Last_Changed_At from a given timestamp).
for example, Steve with given time 11:23:00, will query all the dogs of Steve's friends ordered by the timestamp and only below 11:23:00. Oh, And i dont want that dogs will appear twice. Any one can give me some clue?