Jump to content

Help limiting inner join


SamiBH

Recommended Posts

Hello,

 

I need help limiting inner join.

 

Table:

users:                                              files:

uid                                                    fid

left

active

........................

uid                      =                            fid

........................

my query:

 

Code:

 

SELECT uid
FROM users AS u
INNER JOIN files AS x ON u.uid = x.fid
WHERE u.left = '0'
AND u.active = '1'
ORDER BY `u`.`uid` ASC

 

 

 

result:

uid

3

3

3

3

7

47

47

47

47

47

47

47

47

47

47

 

I need to limit INNER JOIN to 5 only. like:

 

uid

3

3

3

3

7

47

47

47

47

47

 

If anyone could help me I will be very grateful

 

thank you

Link to comment
Share on other sites

 

 

thank you for the reply

 

Are the 5 always the same, or are they different? If different, how so?

 

the query now prints 300 uid >>> no problem here

some of the users have more than 5 active files . so their "uid" will show up more than 5 times

I need to limit the user to only 5

 

 

There is a LIMIT clause in MySQL. I assume you are using that. If not, in MSSQL it's TOP.

 

I'm using MySQL

Tried to use LIMIT

 

SELECT uid
FROM users AS u
INNER JOIN files AS x ON u.uid = x.fid
WHERE u.left = '0'
AND u.active = '1'
ORDER BY `u`.`uid` ASC
LIMIT 5

 

but this will limit the query to 5 instead of 300

I need to limit the inner join but don't know how  :shrug:

Link to comment
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.