and 和 or

where 子句优先处理and,再处理or

1
2
3
select prod_name, prod_price
from products
where vend_id = 1002 or vend_id=1003 and prod_price>=10

可以看成是:

1
2
3
select prod_name, prod_price
from products
where (vend_id = 1002) or (vend_id=1003 and prod_price>=10)

in操作符

1
select username from user where uid in (1, 2, 3);

将要查询的值放在一个括号中

  • in操作符一般比or操作符快
  • in最大的优点是可以包含其他select语句

not 操作符