查询表中所有数据
SELECT * FROM user;
查询表中某个字段的数据
SELECT username,id FROM user;
where的使用
SELECT * FROM user WHERE id>10;
SELECT * FROM user WHERE id=10;
AND表示且;OR表示或
SELECT * FROM user WHERE id=10 AND group_id = 0;
SELECT * FROM user WHERE id=10 OR group_id = 0;
模糊查询LIKE , %:表示0到多个字符;_:表示单个字符
SELECT * FROM user WHERE nickname LIKE '_d%';
IN,查找符合条件的数据
SELECT * FROM user WHERE nickname IN ('admin');
NOT IN, 查找不符合条件的数据
SELECT * FROM user WHERE nickname NOT IN ('admin');
BETWEEN...AND...,查找某个范围内的数据
SELECT * FROM user WHERE id BETWEEN 2 AND 10 ;
IS NULL,IS NOT NULL;NULL空值比较的时候,不能使用“=”号,需要使用IS NULL或IS NOT NULL。
SELECT * FROM user WHERE birthday IS NULL ; //birthday 值为null的数据
SELECT * FROM user WHERE birthday IS NOT NULL ; // birthday 值不为null的数据