在SQL server 2008中,In的用法也是相當重要的。它查詢的是若幹個孤立的值。下面我以幾個例子說明一下。
--查詢工資在1500,3000和5000的三種的工資
select * from emp
wheresal in(1500,3000,5000)
--等價于
select * from emp
wheresal =1500 or sal =3000 or sal=5000
查詢工資不是1500,3000,5000的
select * from emp
wheresal not in(1500,3000,5000)
--等價于
select * from emp
wheresal <>1500 and sal <>3000 and sal<>5000
補充:
--資料庫中不等于有兩種表示:!= 和 <>
--如果使用and和or代替in的用法:對或取反是并且 非并且是或
下面是上述代碼的實作結果截圖。
