blog post

To limit the number of rows use the WHERE clause.
The WHERE clause filters for rows that meet certain criteria.
WHERE is followed by a condition that returns either true or false.
WHERE is used with SELECT, UPDATE, and DELETE.

The SQL WHERE syntax

A WHERE clause with a SELECT statement:
SELECT column-names
  FROM table-name
 WHERE condition

A WHERE clause with an UPDATE statement:
UPDATE table-name
   SET column-name = value
 WHERE condition

A WHERE clause with a DELETE statement:
DELETE table-name
 WHERE condition

SQL WHERE Clause Examples

Problem: List the customers in Sweden
SELECT Id, FirstName, LastName, City, Country, Phone
  FROM Customer
 WHERE Country = 'Sweden'

Problem: Update the city to Sydney for supplier Pavlova, Ltd.
 
UPDATE Supplier
   SET City = 'Sydney'
 WHERE Name = 'Pavlova, Ltd.'

Problem: Delete all products with unit price higher than 50.
DELETE FROM Product
 WHERE UnitPrice > 50


Note: Referential integrity may prevent this deletion.
A better approach may be to discontinue the product, that is, set IsDiscontinued to true.

  • Share This Story


Pleas give your valuable comments to improve the contents.

about author

Atul kumar shukla


I'm Atul Kumar Shukla, working as a web developer.
Welcome to my Blog. This is my personal blog where i post my own questions and answers , articles about ASP.Net., SQL Server, HTML, CSS, Jquery and many more..

Visit Profile

Leave a comment

Name
E-mail
Url
Message

Get More Stuff
Subscribing to the TheOneblogs newsletter and get intersting stuff and updates to your email inbox.
Your Email

 

Style Switcher

Change Color

×! We use cookies to improve your user experience. More information