首页 > 代码库 > IN 查询
IN 查询
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 查询
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。