To limit the number of lines, you can user the clauses LIMIT
,TOP
and ROWNUM
. Ex:
SELECT estado, num_ocorrencia
FROM bra_ocorrencias
WHERE nome like 'João'
LIMIT 5
ORDER BY num_ocorrencia DESC
Or
SELECT estado, num_ocorrencia
TOP 5
FROM bra_ocorrencias
WHERE nome like 'João'
ORDER BY num_ocorrencia DESC;
Or
SELECT estado, num_ocorrencia
FROM bra_ocorrencias
WHERE nome like 'João'
AND ROWNUM <= 5
ORDER BY num_ocorrencia DESC
Reference
Edited
As informed in the other responses, of the 3 clauses cited, the PostgreSQL
supports only the LIMIT
.
There is also the possibility to use the FETCH:
SELECT *
FROM bra_ocorrencias
ORDER BY num_ocorrencia DESC
FETCH 5 ROWS ONLY
Take a look at SELECT, TOP and ROWNUM
– reisdev
Add the clause
LIMIT 5
– Mauro Alexandre
@Matheusreis thinking of large-scale data performance, can you tell me how best to make this return?
– Rafael Brito