1. Grammar
SELECT what to query from the table name;
Similar to Java: System.out.println (something to print);
2. Features
① The result of a select query is a virtual table, not a real existence.
② to query can be a constant value, can be an expression, can be a field, can be a function.
3. Querying a single field in a table
SELECT last_name from Employees;
4. Querying multiple fields in a table
SELECT Last_name,salary,email from Employees;
5. Querying all fields in the table
SELECT * FROM Employees;
6. Query constant Value
SELECT ' John ';
7. Query expression
SELECT 100%98;
8. Query function
SELECT VERSION ();
9, from the alias
① Easy to understand
② If the field you want to query has the same name, you can distinguish it by using an alias
Mode one: Use as
SELECT Last_Name as surname, first_name as name from employees;
Way two: Use spaces
SELECT last_name Surname, first_name name from employees;
Case: Query salary, display results as out put, enclosed in double quotes
Select salary as "out put" from employees;
10, go to Heavy
Case: Querying all the department numbers involved in the employee table
SELECT DISTINCT department_id from employees;
11, + Number of the role
The + sign in Java:
① operator with two operands of numeric type
② connector, as long as one operand is a string
MySQL in the + number:
There is only one function: operator
Select 100+90; Two operands are numeric, then add operation
Select ' 123 ' +90; if one of the characters is a character type, try to convert the character value into a numeric type, and if the conversion succeeds, continue with the addition operation
Select ' John ' +90; Converts a character value to 0 if the conversion fails
Select Null+10; As long as one of the two is null, the result must be null
12, CONCAT
Case: Query employee name and last name concatenated into a field and displayed as name
SELECT CONCAT (last_name,first_name) as name from employees;
If you concatenate one more empty field, the result is null
Workaround, use the Ifnull function
MySQL (iii) DQL basic query