here are some additional clause in the SQL language that can be used to simplify queries by decrease the use of the single Operator repeatly. One of them is IN clause.

IN clause is used to simplify the queries if you want to select data that meet a large number of options. That means IN function helps reduce the need to use multiple OR conditions.

The SQL syntax for the IN operator is:

SELECT [COLUMN NAME] FROM [TABLE NAME]
WHERE [COLUMN] IN ( [VALUE LIST] )

EXAMPLE :

We would like to display all information in IT Department OR Marketing.

Table GameScores

PlayerName Department Scores
Jason IT 3000
Irene IT 1500
Jane Marketing 1000
David Marketing 2500
Paul HR 2000
James HR 2000

SQL statement :

SELECT * FROM GameScores
WHERE Department IN ('IT','Marketing')

Result:

PlayerName Department Scores
Jason IT 3000
Irene IT 1500
Jane Marketing 1000
David Marketing 2500

Actually, This SQL statement below also can show the same results.

SELECT * FROM GameScores
WHERE Department ='IT' OR Department ='Marketing'

Why we should use IN clause?
We should use IN comparisons instead of mutiple comparisons linked using OR whenever possible in order to improve maintainability of our queries. Adding additional value to an IN clause is much easier than repeatly the OR clauses. The code also easier to read as well.

最新文章

  1. 【转】Oracle表分区
  2. php 连接mongodb 增查改删操作
  3. Linux及安全期中总结
  4. 创建link server链接服务器碰到的问题及解决办法
  5. Android adapter适配器的使用
  6. --使用oracle数据先要创建表空间
  7. ASP.NET Core 2.0 in Docker on Windows Container
  8. protobuf 编码实现解析(java)
  9. windows NLB实现MSSQL读写分离--从数据库集群读负载均衡
  10. Python中四种样式的99乘法表
  11. luogu P5291 [十二省联考2019]希望
  12. 快速部署docker
  13. Java文件File类学习总结
  14. Typecho 独立页面 添加自定义模板
  15. 奔跑吧vivado
  16. struts2值栈ValueStack中都有哪些东西?
  17. 【bzoj2034】 2009国家集训队—最大收益
  18. cdoj1638 红藕香残玉簟秋,轻解罗裳,独上兰舟。
  19. codeforces600E Lomsat gelral
  20. java动态代理的实现以及原理

热门文章

  1. python定制类(1):__getitem__和slice切片
  2. Implementing x / 6 Using Only Bit Manipulations
  3. JavaScript with JSONPath
  4. redux 初步理解
  5. Redis学习篇(一)之String类型及其操作
  6. PHP生成短网地址
  7. Hive伪分布式下安装
  8. java 高并发 订单编号递增(解决方案)
  9. MySQL同步状态双Yes的假象及seconds_behind_master的含义
  10. HTML、XML、XHTML 有什么区别?