SELECT * FROM table_name WHERE column_name = 'value'; SELECT * FROM table_name WHERE column_name LIKE '%value%'; SELECT * FROM table_name WHERE column_name IN ('value1', 'value2', 'value3'); SELECT * FROM table_name WHERE condition1 AND condition2; SELECT * FROM table_name WHERE condition1 OR condition2;
以上代码分别介绍了根据某一列的值相等、包含某个值、属于一组值中的其中一个、同时满足两个条件、两个条件之一为真的查询方法。
SELECT * FROM table_name WHERE column_name IS NULL; SELECT * FROM table_name WHERE column_name IS NOT NULL;
这两行代码分别查询这个列的值是NULL或不是NULL的行。
SELECT * FROM table_name WHERE column_name BETWEEN value1 AND value2; SELECT * FROM table_name WHERE column_name NOT BETWEEN value1 AND value2;
这两行代码分别查询满足该列的值在value1和value2之间或不在该范围内的行。
SELECT * FROM table_name WHERE column_name = 'value' AND column_name2 = 'value2'; SELECT * FROM table_name WHERE column_name = 'value' OR column_name2 = 'value2'; SELECT * FROM table_name WHERE NOT column_name = 'value';
这三行代码分别查询值为value且值为value2的行,值为value或值为value2的行,值不为value的行。