* # DQL language
Display table structure desc table;
Query constant values
select 100;
select 'python';
Copy the code
Query expression (four operations)
select 100*98;
Copy the code
Query function
seelct version();
Copy the code
names
/* Easy to understand if the fields to be queried have the same name, alias can distinguish */
Methods a
Select 100*98 as; Select first_name as surname,last_name as name from employees;Copy the code
Way 2
Select 100*98; Select first_name,last_name from empl0yees;Copy the code
SQL > select * from salary; SQL > select * from salary;
select salary as 'out put' from employees;
Copy the code
duplicate removal
Example: Query all department numbers involved in the employee table
select distinct department_id from employees;
Copy the code
Example of the function of ‘+’ : Query the first and last names of employees and join them as one field
/ *
Mysql uses’ + ‘as the operator
Both numbers are of numerical type
If one of the characters is a character, the character is converted to a numeric value to continue the operation
If the conversion fails, the character is converted to 0
If either party is null, the result must be NULL
* /
Splicing functions:
concat(str1,str2...) Select concat(first_name,last_name) as name from employees;Copy the code
Conditions of the query
Select * from table where (select * from table);Copy the code
1. Conditional expression filtering:
Conditional operatorCopy the code
3. Logical expression filtering
Logical operators: && | |! Or "and or not.Copy the code
3, fuzzy query
Like between in is NULL Safely equal to: <=> You can identify null values and common valuesCopy the code
The sorting
Select * from table where order by sort asc\descCopy the code
Multifield sort
Select * from table where order by asc\desc, asc\descCopy the code
Order by: order by: order by: order by: order by: order by
DML (add delete change) #DDL #TCL