MySQL syntax of the query conditions
1, grammar:
①SELECT query list (may include: field, an expression, a constant value, a few pieces together constitute the table)
②FROM table (original table)
③WHERE (understood as filter criteria when ... = TRUE or filter = FALSE)
Screening conditions
order of execution: 231
2. Conditional Expression Filter
Conditional operator:> <= <=> =
! = Or <> (not equal represented)
3. Filter by logical expressions
Operatively connected to the conditional expression
in Java:! && ||
and
in MySQL: and or not
&& and and: both conditions are true, the result is true, otherwise it is false
|| and or: as long as a condition is true the result is true, otherwise it is false
and not:! If the condition itself is false, evaluates to true, false otherwise
4. Fuzzy query
like the general and the use of wildcards
Wildcard:
% any number of characters, including 0, represents not null
_ any single character
/ *
Case 3: The second query employee names for the characters _ employees name
* /
the SELECT
last_name,
salary
the FROM
the Employees
the WHERE
last_name the LIKE ' Katex the parse error: the After the Expected Group' _ 'AT position 1: _%' ESCAPE ' ' ;
last_name the LIKE ' _%';
\ Right slash character translation
when conditions can be translated using the ESCAPE statement need the right slash characters
5、between and
Features:
1. The statement can be improved conciseness
2 comprises a critical value
3 equivalent to> = <=
type must be the same, or may be implicit conversion
6、in
Meaning: to determine whether the value of a field of an item in the list of
features:
1. increase in concise statement of
the type of value 2.in list (that is, fields) must be unified or compatible (can be implicitly converted)
3. = number equivalent to
4 does not support wildcards
7、is null
1 =! = <> Null value is determined not
need
2.is null or is not null null value based
3.is null and indivisible
/ *
Case 1: Query the employees name does not pay and bonus rate
* /
the SELECT
last_name,
commission_pct
the FROM
the Employees
the WHERE
commission_pct = NULL;
- ------------------- not show this results because the number can not be determined null value = --------------------
the SELECT
last_name,
a commission_pct
the FROM
the Employees
the WHERE
a commission_pct the IS nULL;
- -------- ------------------- query has --------------------------- bonus -----
the SELECT
last_name,
a commission_pct
the FROM
the Employees
the WHERE
a commission_pct the IS the NOT NULL;
------------- can not be used as such, is an integral and null ----------------------- ↓
- the SELECT
- last_name,
- a commission_pct
- the FROM
- the Employees
- the WHERE
- the salary the IS 12,000;
8, <=> Security equal
Meaning: judging whether equal, returns true if false otherwise equal
effects:
1. Analyzing the null value may be
2. Analyzing common value may further
disadvantages:
poor readability
NULL PK <=> the IS
the IS NULL; null values only be used to determine recommended
<=>; Analyzing may be a null value, and based on normal values, lower readability
9, IFNULL determines whether the air
IFNULL (A, B) if A is empty, then the result is IFNULL B, A and vice versa is not empty then the result is A IFNULL
Classic interview questions ask:
SELECT * FROM employees;
and
SELECT * FROM employees WHERE commission_pct LIKE ' %%' AND last_name LIKE '%%';
the results are the same?
Not the same, if the field has a null value is determined, empty. Then the result is not the same
% Represents any number of characters can not express null
If you replace or judgment result is the same in all fields