Search code examples
sqlpostgresqlwhere-clausesql-limit

Where would the Limit statement go? Postgresql


Short Question, where would the limit clause go in Postgresql? I want to limit the amount of rows to 10, but it is giving me an error when I do;

From this_table x
    join this_table y
    on x.no = y.no


where x.no = '7'
Limit 10
group by x.location
order by x.location

It's giving me a syntax error at or near "where"

(If requested, I could add the select statement.


Solution

  • limit is the last clause in a select query, so it goes after the order by:

    select <whatever>
    From this_table x
        join this_table y
        on x.no = y.no
    where x.no = '7'
    group by x.location
    order by x.location
    Limit 10;