1

I am looking for a solution to use sub query in limit value.

Ex:

SELECT *
FROM `user`
WHERE usertype='6' LIMIT
  (SELECT count(*) FROM allowed WHERE usertype='6')

Is there any other way to use a sub Query in LIMIT. I tried the above Query but Its not working.

4
  • Do it in 2 steps: 1. select the limit from the 1-st table, 2. use it in the 2-nd query Commented Sep 18, 2014 at 10:42
  • I need it to be in single query is that possible. I can do that by two different queries.. Commented Sep 18, 2014 at 10:43
  • possible duplicate of Variable LIMIT Clause in MySQL Commented Sep 18, 2014 at 10:45
  • 1
    do you have user_id in allowed table? Commented Sep 18, 2014 at 11:06

1 Answer 1

1

This is not possible with MySql; you have to use a stored procedure/prepared statement as workaround.

Lots of people have requested this:

http://bugs.mysql.com/bug.php?id=8094

but as you see from the bug listing, this is still open.

EDIT: actually, it seems to have been added in version 5.5.6:

http://bugs.mysql.com/bug.php?id=11918

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.