I need to display the products from the second product onwards. To get the idea, I show an example of the database layout.
id product
1 One
2 Two
3 there
4 Four
5 Five
I need to show the products starting from id -> 2
onwards.
I have tried this way, but it only shows me the product of id -> 2
and not the rest of the products.
Select * from products where id = 2 and active='1' order by id ASC limit 16
If the ID is
autoincrement
(not generated and numeric) it would suffice to obtain the elements that are greater than or equal to 2 , that isID
>=2
First we order the data with
order by id ASC
and then if we make a query saying that heid
has to be greater than and equal to 2 (>=2
) being like thisThe clause
LIMIT
can be used to restrict the number of records that are returned in a querySELECT
. Receive one or two arguments.If we use LIMIT with a single argument, we will be selecting only the
N
first elements of our table.By default, the initial record is
0
, that is, it is0
equivalent to the first record of the table.If we use LIMIT with two arguments, the first argument specifies the first record to return and the second the total number of records to return.
LIMIT
If we use a large enough number as the second parameter, it will select all the records of a table.* The use of
LIMIT
in conjunction with the statement is recommendedORDER BY
to avoid inconsistent results.It seems to me that the best solution in this case is the following query because it returns all the products that are active, from the second to the last one regardless of the table ID. It is a nuance to take into account, especially if it is allowed to delete records from the table and the first record becomes something other than id 1.