2011-09-23 21 views
5

¿Es posible usar LIMIT x con la cláusula WHERE? Si es así, ¿cómo?LÍMITE SQL con la cláusula WHERE

que estoy tratando de hacer esto:

select * from myVIew LIMIT 10 where type=3; 

pero me da el siguiente 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 
+0

¿Qué se supone que debe hacer? – NullUserException

+0

Limite la cantidad de filas devueltas. – capdragon

+0

¿Por qué tiene "MySQL" en el título si está usando PostgreSQL? –

Respuesta

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

Limit debe ser después where clause.

Sintaxis:

SELECT column_name(s) 
FROM table_name 
[WHERE] 
LIMIT number; 
+3

Esto no está permitido en SQL, solo en MySQL –

2
select * from myVIew where type=3 LIMIT 10; 
5

Sí, ¿ha probado esto?

select * from myVIew where type=3 LIMIT 10; 

Mirar here for further reference. LIMIT está después de WHERE y ORDER BY cláusulas, lo cual tiene mucho sentido si te paras a pensarlo: primero tienes que definir tu conjunto de resultados base (filtros y pedidos), luego lo limitas/vez.