Logo 
Search:

SQL Server Articles

Submit Article
Home » Articles » SQL Server » MiscellaneousRSS Feeds

Where clause with select query

Posted By: Sarita Patel     Category: SQL Server     Views: 3057

This article describes use of where clause with select query using different examples.

Where Clause -  Is used to filter data in table. You can't use aggregate function such as SUM(), COUNT() in a WHERE clause.

Example of where clause with select statement

SELECT productid,productname,unitprice 

FROM products 

WHERE unitprice < 18.00

Output

ProductID  ProductName                            UnitPrice

3                 Aniseed Syrup                           10.00

13               Konbu                                           6.00

15               Genen Shouyu                           15.50

16               Pavlova                                      17.45

19               Teatime Chocolate Biscuits      9.20

21               Sir Rodney's Scones                10.00

Above example explains how can we retrieve specific records from a table. We can specify different conditions in where clause as in above example, It retrieves product having unit price less than $18.00. We can also specify more than one conditions in where clause for example


Example 2 : Filtering records using multiple conditions in where clause

SELECT productid,productname,unitprice 

FROM products 

WHERE 

unitprice < 18.00 AND

(productname like 'a%' OR productname like 'c%')

Output

ProductID  ProductName       UnitPrice

3                 Aniseed Syrup    10.00

48              Chocolade           12.75

Above example explains how we can retrieve data using multiple conditions in where clause. It filters  product having unit price less than $18.00 and product name starting from 'a' and 'c' characters. 

  
Share: 


Didn't find what you were looking for? Find more on Where clause with select query Or get search suggestion and latest updates.

Sarita Patel
Sarita Patel author of Where clause with select query is from United States.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!