当前位置:网站首页>MySQL - Basic select statement

MySQL - Basic select statement

2022-06-11 19:35:00 Can't learn java

1、DQL(Data Query Language: Data query language )

  • All query operations use it SELECT
  • The core language in database , The most important statement
  • The most frequently used statement

2、 Specify query fields

SELECT * FROM  Table name ;	--  Query all field information in the table 

SELECT  Field 1, Field 2 FROM  Table name ;	--  Query all the information of the specified field 

SELECT  Field 1 AS  Alias 1, Field 2 AS  Alias 2 FROM  Table name ;		--  Alias fields ( You can also alias a table )

SELECT CONCAT(' character string 1',' character string 2',···) ;		--  String concatenation 

SELECT DISTINCT  Field name 1 FROM  Table name ;		--  Duplicate data found , duplicate removal 

3、where Conditional clause

  • effect : Retrieve data eligible Value
  • Logical operators :
    Operator grammar describe
    and / &&a and b / a&&b Logic and , All true , The result is true
    or / ||a or b / a||b Logic or , One of them is true , The result is true
    not / !not a / !a Logic is not , True or false , False is true
  • Fuzzy query :
    Operator grammar describe
    IS NULLa is null If the operator is NULL, The result is true
    IS NOT NULLa is not null If the operator is not NULL, The result is true
    BETWEENa between b and c if a stay b and c Between , The result is true
    LIKEa like bSQL matching , If ah matches b, The result is true
    INa in (a1,a2,a3···) hypothesis a stay a1 perhaps a2··· One of the values , The result is true

4、 League table query

operation describe
inner join If there is at least one match in the table , Just go back
left join All values are returned from the left table , Even if there is no match in the right table
right join All values are returned from the right table , Even if there is no match in the left table
  • Connect your own table to your own table , The core : One table can be split into two identical tables

    SELECT a. Field name  AS ' Parent column ' b. Field name  AS ' Sub column '
    FROM  Table name 1 AS a,  Table name 1 AS b
    WHERE a. Field name 1 = b. Field name 2;
    

5、 Paging and sorting

  • Sort :ORDER BY

    SELECT  Field name 1, Field name 2,··· FROM  Table name 
    ORDER BY  Field name 1 ASC/DESC[, Field name 2 ASC/DESC,···];
    
  • Pagination :LIMIT

    SELECT * FROM  Table name  LIMIT  Starting value , Page size ;
    

6、 Subquery

  • where The latter condition is select A result set :

    SELECT  Field name  FROM  Table name  WHERE  Field name 1 = 
    (SELECT  Field name 1 FROM  Table name  WHERE  Field name 1=  Conditional expression );
    

7、 Aggregate functions

SELECT  Field name 1,AVG( Field name 1) FROM  Table name  GROUP BY  Field name 1 [HAVING  Conditional expression ];
原网站

版权声明
本文为[Can't learn java]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111932008861.html