自学sql

条件查询

2017-08-29  本文已影响0人  JooYip

WHERE

SELECT column01[, column02, column03...] FROM table_name WHERE condition;

WHERE与ORDER BY配合的时候,order by在where后面。


比较符

WHERE中的条件,有很多比较符,可提的就是!=与<>是一个意思,表示不等于。


BETWEEN AND

WHERE column_name BETWEEN start AND end;

WHERE column_name >= start and column_name <=end; --这俩等价


检查为空

WHERE column_name IS NULL; --- IS NOT NULL


WHERE AND / WHERE OR

WHERE AND优先级比WHERE OR高,结合使用有顺序要求的,使用括号。

WHERE condition01 OR condition02 AND condition03;

-- 与

WHERE condition01 OR (condition02 AND condition03); -- 是等价的。AND优先级比OR要高。


WHERE IN

其实就是简写的OR

例如:

WHERE price in(10, 11, 4); 


NOT

WHERE NOT condition; -- 否定条件

NOT IN(...);

NOT BETWEEN AND;

NOT EXISTS;


LIKE

WHERE name LIKE '%z_'; --%表示n个字符,_表示一个字符

上一篇下一篇

猜你喜欢

热点阅读