Reputation: 131
I'm listing products from my database where I select the latest product as a big feature. The rest are sorted by latest product.
So I have two querys which looks like this.
SELECT * FROM products ORDER BY product_id DESC LIMIT 1
and
SELECT * FROM products ORDER BY product_id DESC LIMIT 4
However... This makes the latest product appear twice in my current layout. (The feature).
How do I tell the second query to skip the latest entry?
Upvotes: 0
Views: 654
Reputation: 28864
We can specify the LIMIT
clause to start at second row instead, and then fetch next 4 rows.
SELECT * FROM products ORDER BY product_id DESC LIMIT 1,4
Syntax is:
[LIMIT {[offset,] row_count | row_count OFFSET offset}]
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return.
The offset of the initial row is 0 (not 1):
Upvotes: 4