G-SQL SQL WHERE IN 절

2017.06.10 18:00

가을의곰 조회 수:4280

 

SQL WHERE IN 절

  • WHERE IN returns values that matches values in a list or subquery.
  • WHERE IN is a shorthand for multiple OR conditions.

The definitive guide
for data professionals 

 
 

The SQL WHERE IN syntax


The general syntax is: 


 
  1. SELECT column-names
  2. FROM table-name
  3. WHERE column-name IN (values)


 


PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued

 

SQL WHERE IN Examples




Problem: List all suppliers from the USA, UK, OR Japan


 
  1. SELECT Id, CompanyName, City, Country
  2. FROM Supplier
  3. WHERE Country IN ('USA', 'UK', 'Japan')



Results: 8 records. 


 

Id CompanyName City Country
1 Exotic Liquids London UK
2 New Orleans Cajun Delights New Orleans USA
3 Grandma Kelly's Homestead Ann Arbor USA
4 Tokyo Traders Tokyo Japan
6 Mayumi's Osaka Japan
8 Specialty Biscuits, Ltd. Manchester UK
16 Bigfoot Breweries Bend USA
19 New England Seafood Cannery Boston USA


 


PRODUCT
Id
ProductName
SupplierId
UnitPrice
Package
IsDiscontinued



Problem: List all products that are not exactly , , , , or

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com


 
  1. SELECT Id, ProductName, UnitPrice
  2. FROM Product
  3. WHERE UnitPrice NOT IN (10,20,30,40,50)



Results: 72 records. 


 

Id ProductName UnitPrice
1 Chai 18.00
2 Chang 19.00
4 Chef Anton's Cajun Seasoning 22.00
5 Chef Anton's Gumbo Mix 21.35
6 Grandma's Boysenberry Spread 25.00


 


SUPPLIER
Id
CompanyName
ContactName
City
Country
Phone
Fax
CUSTOMER
Id
FirstName
LastName
City
Country
Phone



Problem: List all customers that are from 
the same countries as the suppliers.


 
  1. SELECT Id, FirstName, LastName, Country
  2. FROM Customer
  3. WHERE Country IN
  4. (SELECT Country
  5. FROM Supplier)



Results: 91 records. 


 

Id FirstName LastName Country
1 Maria Anders Germany
4 Thomas Hardy UK
5 Christina Berglund Sweden
6 Hanna Moos Germany
7 Frédérique Citeaux France

 

 

[출처] http://www.dofactory.com/sql/where-in

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED