LIMIT (MySQL)
Naar navigatie springen
Naar zoeken springen
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Argumenten:
- Eerste getal: Begin
- Tweede getal: #Records - niet laatste record!
Dus:
LIMIT 0,10 = LIMIT 0,5 & LIMIT 5,5
select * from tmp limit 0,10; select * from tmp limit 0,5; select * from tmp limit 5,5;
Hij begint bij 0!
Het eerste record heeft volgnummer 0, niet volgnummer 1. Heel onhandig.
Dit selecteert de eerste tien records:
select * from tmp limit 0,10
Dit selecteert record 2 tot en met 11:
select * from tmp limit 1,10
Scripts vs. sprocs
Onduidelijk of je hier wel of niet een variable voor kunt gebruiken. In sprocs lijkt dat te werken, maar in scripts niet.
Voorbeeld limit-variable in een sproc
################################################################################################ # Limit ################################################################################################ # delete from root_tmp where sku not in ( select sku from ( select sku from root_tmp limit 0, in_limit ) foo );
Sproc: Input-variable vs. local variable
Dit werkt niet:
insert into root_tmp (sku, sku_oem, product_group) select sku, sku, "oem" from product_oem_201808 limit 0, @products_per_group;
maar dit wel:
insert into root_tmp (sku, sku_oem, product_group) select sku, sku, "oem" from product_oem_201808 limit 0, in_limit;