SQL Transact – Where IN clauseJust a tiny word, but what a difference IN makes to your transact statement. On this page we combine WHERE and IN to make a more sophisticated SQL filter. Lesson 1 – Filtering companies in specific countries.The situation is: You need to contact your customers buy only if they are in 4 Central European countries. — SQL statement to find customers in Austria, Belgium, Germany, and Italy
USE Northwind
Learning PointsNote 1: What I like is the efficiency of using SQL’s IN rather than multiple select statements. Note 2: The choice of round brackets to (enclose all the countries). Note 3: Each country has its own set of single quotes and is separated from its neibour by a comma. Note 4: Incidentally, we filtered the columns to just companyname and country. Another SQL Transact condition: Where BETWEENOn a completely different tack, you could try: Where BETWEEN Example: — SQL Transact statement to find prices between 15 and 25
USE Northwind
Guy’s Out TakesIf you like a challenge, troubleshoot this transact statement and see if you can correct the error. SQL Transact Out Take 1Why does this transact statement not execute? — SQL Statement to find customers in Austria, Belgium, Germany, and Italy
USE Northwind
Answer: What wee need is countRy not county. SQL Transact Out Take 2Why won’t this statement run? — SQL Statement to find prices between 15 and 25
USE Northwind
Answer: The FROM clause should be on the line before the WHERE clause: here is the correct SQL Transact sequence. FROM Products WHERE unitprice BETWEEN 15 AND 25.
|
|
See also