Jump to content

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

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.