SamiBH Posted February 11, 2011 Share Posted February 11, 2011 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 Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 11, 2011 Share Posted February 11, 2011 Are the 5 always the same, or are they different? If different, how so? There is a LIMIT clause in MySQL. I assume you are using that. If not, in MSSQL it's TOP. Quote Link to comment Share on other sites More sharing options...
SamiBH Posted February 11, 2011 Author Share Posted February 11, 2011 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 Quote Link to comment Share on other sites More sharing options...
fenway Posted February 13, 2011 Share Posted February 13, 2011 You can't limit an inner join -- you''ll need to use a derived table for table. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.