Article Directory
where supported operators
- Comparison Operators
- Logical Operators
- Fuzzy query
- Range queries
- Empty judgment
Format where the query conditions
select * from 表名 where 条件;
例:
select * from students where id = 1;
Comparison Operators
- Equal =
- Greater than>
- Greater than or equal to> =
- Less than <
- Less than or equal to <=
- Is not equal! = Or <>
例1:查询编号大于3的学生:
select * from students where id > 3;
例2:查询编号不大于4的学生:
select * from students where id <= 4;
例3:查询姓名不是“黄蓉”的学生:
select * from students where name != '黄蓉';
例4:查询没被删除的学生:
select * from students where is_delete=0;
Logical operator query
- and
- or
- not
Example 1: Query number of female students is greater than 3:
select * from students where id > 3 and gender=0;
Example 2: Query number less than 2 or not students are deleted:
select * from students where id < 2 or is_delete=0;
Example 3: The query is not the age of the students between 23 and 24 years old:
select * from students where not (age >= 23and age <= 24);
Description:
Determining a plurality of conditions as a whole desired, may be incorporated '()'.
Fuzzy query
- like keyword fuzzy query
- % Represents any number of characters
- _ Represents an arbitrary character
Example 1: Query student surnamed Huang:
select * from students where name like '黄%';
Example 2: Query surnamed Huang and "name" is a word of student:
select * from students where name like '黄_';
Example 3: The query or call surnamed Huang Qi what students:
select * from students where name like '黄%' or name like '%琦';
Range queries
- between ... and ... express queries within a continuous range
- in indicates that the query in a non-continuous range
Example 1: Query number of students 3-8:
select * from students where id between 3 and 8;
or
select * from students where id>=3 and id<=8;
Example 2: query number is not boys 3 to 8:
select * from students where (not id between 3 and 8) and gender='男';
or
select * from students where not (id>=3 and id<=8);
Empty judgment
- Is determined using the blank is null
- Analyzing the use of non-null is not null
Example 1: The query does not fill out the student height:
select * from students where height is null;
note:
1 can not be used is determined where height = null null
2 can not be used where height! = Null determined non-empty
3. null is not equal to 'empty string