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
https://forums.phpfreaks.com/topic/227324-help-limiting-inner-join/
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:

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.