13

Is it possible to use LIMIT x with the WHERE clause? If so, how?

I'm trying to do this:

select * from myVIew LIMIT 10 where type=3;

But i get the following error:

ERROR:  syntax error at or near "where"
LINE 2: where type=3;
        ^
********** Error **********
ERROR: syntax error at or near "where"
SQL state: 42601
Character: 44
3
  • Limit the amount of rows returned. Commented Sep 23, 2011 at 17:45
  • Why do you have "MySQL" in the title if you are using PostgreSQL? Commented Dec 18, 2012 at 13:21
  • @a_horse_with_no_name I had 'SQL' Someone edited it. :/ Thanks, changed it back. Commented Dec 18, 2012 at 15:33

3 Answers 3

23
select * from myVIew  where type=3 LIMIT 10;

Limit should be after where clause.

Syntax :

SELECT column_name(s)
FROM table_name
[WHERE]
LIMIT number;
Sign up to request clarification or add additional context in comments.

1 Comment

This is not allowed in SQL, only in MySQL
5

Yes, have you tried this?

select * from myVIew  where type=3 LIMIT 10;

Look here for further reference. LIMIT is after WHERE and ORDER BY clauses, which makes total sense if you stop and think about it: first you have to define your base result set (filters and orders), then you limit/page it.

1 Comment

"...which makes total sense..." wait I thought we were talking about SQL?
2
 select * from myVIew where type=3  LIMIT 10;

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.