Syntax knowledge of DQL in MySQL learning 8 (paging query)

Article directory

Paging query syntax and application scenarios

Application scenario: Currently displayed data, one page is incomplete, and sql request needs to be submitted in paging
Syntax:
                  Execution order
  select query list Seven
  from table One
  [join type] join table 2 Two
  where filter conditions Three
  group by grouping
  conditions Five
  order by sorting field six
  limit offset, size; eight

(offset: the actual index of the entry to be displayed (the starting index starts from 0, if not filled, the default is 0 
size: the number of entries to be displayed)

Features:
  ①The limit statement is placed at the end of the query statement ②The   number of pages to be displayed by the
  formula , the number of entries per page is size

select query list
 from table
 limit (page - 1 ) * size , size ;

some simple cases

#Case 1: Query the first 5 employee information 
SELECT * FROM employees LIMIT  0 , 5 ;


#Case: Employees with bonus information, and the top 10 with higher salary are displayed 
SELECT * FROM employees WHERE commission_pct IS  NOT  NULL  ORDER  BY salary DESC  LIMIT  10 ;

Please give me a thumbs up and let’s go

Leave a Comment

Your email address will not be published. Required fields are marked *