2011-09-23 17 views
5

E 'possibile usare LIMIT x con la clausola WHERE? Se sì, come?SQL con clausola WHERE

che sto cercando di fare questo:

select * from myVIew LIMIT 10 where type=3; 

ma ottengo il seguente errore:

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

cosa dovrebbe fare? – NullUserException

+0

Limitare la quantità di righe restituite. – capdragon

+0

Perché hai "MySQL" nel titolo se si utilizza PostgreSQL? –

risposta

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

Limit dovrebbe essere dopo where clause.

Sintassi:

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

Ciò non è consentito in SQL, solo in MySQL –

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

Sì, avete provato questo?

select * from myVIew where type=3 LIMIT 10; 

Look here for further reference. LIMIT è dopo le clausole WHERE e ORDER BY, il che ha perfettamente senso se ci si ferma e ci si pensa: per prima cosa è necessario definire il set di risultati di base (filtri e ordini), quindi limitare/pagina.