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
So the key thing to notice is the specific order and arrangement of the SQL statement: just as FROM comes after the SELECT clause, LIMIT comes after both.
The SQL LIMIT clause restricts how many rows are returned from a query. The syntax for the LIMIT clause is: SELECT * FROM table LIMIT X;. X represents how many records you want to retrieve. For example, you can use the LIMIT clause to retrieve the top five players on a leaderboard.
SELECT * FROM ( SELECT * FROM yourTableName ORDER BY id DESC LIMIT 10 )Var1 ORDER BY id ASC; Let us now implement the above query. mysql> SELECT * FROM ( -> SELECT * FROM Last10RecordsDemo ORDER BY id DESC LIMIT 10 -> )Var1 -> -> ORDER BY id ASC; The following is the output that displays the last 10 records.
SELECT column_list FROM table_name ORDER BY expression LIMIT n-1, 1; In this syntax, the LIMIT n-1, 1 clause returns 1 row that starts at the row n. For example, the following query returns the employee information who has the second-highest income: SELECT emp_name, city, income FROM employees.
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;
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With