SQL IN
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.
SQL IN的更多相关文章
- 最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目
最近帮客户实施的基于SQL Server AlwaysOn跨机房切换项目 最近一个来自重庆的客户找到走起君,客户的业务是做移动互联网支付,是微信支付收单渠道合作伙伴,数据库里存储的是支付流水和交易流水 ...
- SQL Server 大数据搬迁之文件组备份还原实战
一.本文所涉及的内容(Contents) 本文所涉及的内容(Contents) 背景(Contexts) 解决方案(Solution) 搬迁步骤(Procedure) 搬迁脚本(SQL Codes) ...
- Sql Server系列:分区表操作
1. 分区表简介 分区表在逻辑上是一个表,而物理上是多个表.从用户角度来看,分区表和普通表是一样的.使用分区表的主要目的是为改善大型表以及具有多个访问模式的表的可伸缩性和可管理性. 分区表是把数据按设 ...
- SQL Server中的高可用性(2)----文件与文件组
在谈到SQL Server的高可用性之前,我们首先要谈一谈单实例的高可用性.在单实例的高可用性中,不可忽略的就是文件和文件组的高可用性.SQL Server允许在某些文件损坏或离线的情况下,允 ...
- EntityFramework Core Raw SQL
前言 本节我们来讲讲EF Core中的原始查询,目前在项目中对于简单的查询直接通过EF就可以解决,但是涉及到多表查询时为了一步到位就采用了原始查询的方式进行.下面我们一起来看看. EntityFram ...
- 从0开始搭建SQL Server AlwaysOn 第一篇(配置域控)
从0开始搭建SQL Server AlwaysOn 第一篇(配置域控) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www.cnb ...
- 从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群)
从0开始搭建SQL Server AlwaysOn 第二篇(配置故障转移集群) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...
- 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)
从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...
- 从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点)
从0开始搭建SQL Server AlwaysOn 第四篇(配置异地机房节点) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://www ...
- SQL Server on Linux 理由浅析
SQL Server on Linux 理由浅析 今天的爆炸性新闻<SQL Server on Linux>基本上在各大科技媒体上刷屏了 大家看到这个新闻都觉得非常震精,而美股,今天微软开 ...
随机推荐
- 【C#】缓存数据
namespace WpfCopy.Controls { public class CacheFileEventArgs : EventArgs { public bool IsFaulted { g ...
- 【WPF】ListView自定义分页
XAML: <Grid> <Grid.RowDefinitions> <RowDefinition Height="*"/> <RowDe ...
- chakra在vs2017中编译出现的问题
转:http://blog.csdn.net/ink_cherry/article/details/73437981 1.无法找到vs2010生成工具 MSB8020 无法找到 Visual Stud ...
- IntelliJ IDEA 编译程序出现 非法字符 的 解决方法(转)
百度到很多方法,比如(删了文件重新建:先改成GBK再UTF8:粘贴到notpad++上改utf8),但都没有解决问题.下面这种方法确实有效,先记下来,如果有其他好方法将来在补充…… 文章来源: ht ...
- 快速配置webpack多入口脚手架
背景 当我们基于vue开发单个项目时,我们会init一个vue-cli,但当我们想在其他项目里共用这套模板时,就需要重新init一个,或者clone过来,这非常不方便,而且当多人开发时,我们希望所有的 ...
- 使用AppCompat项目模版
使用AppCompat项目模版 从Android API 22开始,谷歌推荐使用AppCompatActivity来构建带标题栏的App,而不是原有的ActionBarActivity.如果用户想 ...
- Bakery CodeForces - 707B (最短路的思路题)
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. The ...
- zstuoj 4245 KI的斐波那契
KI的斐波那契 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 550 Solved: 208 Description KI十分喜欢美丽而优雅的斐波那 ...
- android jni 内部 以及 安卓 init 分析
韩梦飞沙 韩亚飞 313134555@qq.com yue31313 han_meng_fei_sha
- 51nod1376 最长上升子序列的数量
机房的人问我树状数组怎么做这题...... 树状数组维护$len, num$表示$LIS$的长度和数量即可 复杂度$O(n \log n)$ 注:$O(n \log n)$二分+单调栈才是真神仙 具体 ...