The
LIMITexpression allows one to limit the number of result set rows in a query. For example:
SELECT contact_id, last_name, first_name FROM contacts WHERE website = 'TechOnTheNet.com' ORDER BY contact_id DESC LIMIT 5;
will select the first
5records from the contacts table where the website isTechOnTheNet.com. Note that the results are sorted bycontact_idin descending order so this means that the 5 largestcontact_idvalues will be returned. If there are other records in the contacts table that have a website value ofTechOnTheNet.com, they will not be returned.If we wanted to select the 5 smallest
contact_idvalues instead of the largest, we could change the sort order as follows:SELECT contact_id, last_name, first_name FROM contacts WHERE website = 'TechOnTheNet.com' ORDER BY contact_id ASC LIMIT 5;Here the results would be sorted by
contact_idin ascending order. So the first 5 smallestcontact_idrecords that have a website ofTechOnTheNet.comwould be returned, and no other records would be returned by this query.Limit with Offset
Though the
OFFSETkeyword is not supported by eXtremeSQL, the notion of theoffsetfunctionality is supported using theLIMITexpression. For example:
SELECT... FROM table LIMIT M,N;
will select the
Nrecords starting from line numberM(whereMis zero-based); in other words skipMresult set rows. Thus
SELECT... FROM table LIMIT 0,N;
is equivalent to:
SELECT... FROM table LIMIT N;