메뉴 닫기

SQL WHERE Clause

The SQL WHERE syntax

A WHERE clause with a SELECT statement:

  1. SELECT columnnames
  2. FROM tablename
  3. WHERE condition

A WHERE clause with an UPDATE statement:

  1. UPDATE tablename
  2. SET columnname = value
  3. WHERE condition

A WHERE clause with a DELETE statement:

  1. DELETE tablename
  2. WHERE condition

 


SQL WHERE Clause Examples

Problem: List the customers in Sweden

  1. SELECT Id, FirstName, LastName, City, Country, Phone
  2. FROM Customer
  3. WHERE Country = ‘Sweden’

Results:  2 records

Id FirstName LastName City Country Phone
5 Christina Berglund Luleå Sweden 0921-12 34 65
24 Maria Larsson Bräcke Sweden 0695-34 67 21

 


Problem: Update the city to Sydney for supplier Pavlova, Ltd.

  1. UPDATE Supplier
  2. SET City = ‘Sydney’
  3. WHERE Name = ‘Pavlova, Ltd.’

Results: 1 record updated.


Problem: Delete all products with unit price higher than $50.

  1. DELETE FROM Product
  2. WHERE UnitPrice > 50

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

1 Comment

  1. Nydia Sesso

    I simply want to say I am just beginner to weblog and really savored you’re web page. Probably I’m going to bookmark your blog post . You certainly come with beneficial well written articles. With thanks for revealing your website page.

댓글 남기기

이메일은 공개되지 않습니다.