MySQL是一種常用的關系型數據庫,對于開發者來說,常常需要進行查詢 判斷操作。下面介紹一些MySQL的查詢 判斷方法。
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的行。