Jump to content

limit by list- sql


felito

Recommended Posts

I am trying this code, that works well.

 

SELECT U.username, U.update_photo
FROM users U

INNER JOIN lists_has_users H 
ON U.id_user = H.users_id_user

INNER JOIN lists L
ON L.id_lists = H.lists_id_lists

WHERE L.users_id_user = ?   

 

Now the problem. This query will select all the users of the lists. What i want is limit the number of output members by list.

 

For example, two members by each list (id_lists).

 

Any idea? thanks

 

Link to comment
https://forums.phpfreaks.com/topic/260038-limit-by-list-sql/
Share on other sites

To clarify.

 

I have this structure:

table users
id_user username update_photo
1 Pedro photo
2 Joao photo
3 Carlos photo
4 José photo
5 António photo
6 Toni photo

table  lists
id_lists name_list users_id_user
1 primeira_lista 9 // owner of the list
2 segunda_lista 9 // owner of the list

table lists_has_users
users_id_user lists_id_lists
1 1 - first
2 1 - second
3 1 --------
4 2 - first
5 2 - second
6 2 --------

 

 

The outuput that I want is:

1 Pedro photo

2 Joao photo

3 Carlos photo

4 José photo

5 António photo

6 Toni photo

 

 

My idea is a sample of two members of each list. If the user want to see more members he can click in view more button that will open a new page with all members of this list.

 

Did you understand what i mean?

Link to comment
https://forums.phpfreaks.com/topic/260038-limit-by-list-sql/#findComment-1333027
Share on other sites

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.