IN 查詢
阿新 • • 發佈:2017-05-24
sel sql from _id apple 6.4 查詢條件 ber 5.7
IN 查詢 :SELECT 字段名1, 字段名2, ...... , 字段名n FROM 表名 WHERE 查詢條件 IN (範圍) ;
mysql> SELECT s_id, f_name, f_price FROM fruits WHERE s_id IN (101,102); +------+------------+---------+ | s_id | f_name | f_price | # 查詢s_id為101和102的記錄 +------+------------+---------+ | 101 | apple | 5.20| | 101 | blackberry | 10.20 | | 102 | orange | 11.20 | | 101 | cherry | 3.20 | | 102 | banana | 10.30 | | 102 | grape | 5.30 | +------+------------+---------+
mysql> SELECT s_id, f_name, f_price FROM fruits WHERE s_id NOT IN (101,102); +------+---------+---------+ | s_id | f_name | f_price | # 與IN相反,用來查詢不在條件範圍內的記錄+------+---------+---------+ | 103 | apricot | 2.20 | | 104 | berry | 7.60 | | 107 | xxxx | 3.60 | | 105 | melon | 8.20 | | 104 | lemon | 6.40 | | 106 | mango | 15.70 | | 105 | xbabay | 2.60 | | 105 | xxtt | 11.60 | | 103 | coconut | 9.20 | | 107 | xbababa | 3.60| +------+---------+---------+
IN 查詢