SQL WHERE AND, OR, NOT Clause

The WHERE with AND, OR, NOT syntax

A WHERE clause with AND:

  1. SELECT columnnames
  2. FROM tablename
  3. WHERE condition1 AND condition2

A WHERE clause with OR:

  1. UPDATE tablename
  2. SET columnname = value
  3. WHERE condition1 OR condition2

A WHERE clause with NOT:

  1. DELETE tablename
  2. WHERE NOT condition

 


 

SQL WHERE with AND, OR, and NOT Examples

Problem: Get customer named Thomas Hardy

  1. SELECT Id, FirstName, LastName, City, Country
  2. FROM Customer
  3. WHERE FirstName = ‘Thomas’ AND LastName = ‘Hardy’

Results: 1 record.

Id FirstName LastName City Country
4 Thomas Hardy London UK

 


Problem: List all customers from Spain or France

  1. SELECT Id, FirstName, LastName, City, Country
  2. FROM Customer
  3. WHERE Country = ‘Spain’ OR Country = ‘France’

Results: 16 records.

Id FirstName LastName City Country
7 Frédérique Citeaux Strasbourg France
8 Martín Sommer Madrid Spain
9 Laurence Lebihan Marseille France
18 Janine Labrune Nantes France
22 Diego Roel Madrid Spain
23 Martine Rancé Lille France

 


Problem: List all customers that are not from the USA

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

Results: 78 records.

Id FirstName LastName City Country
1 Maria Anders Berlin Germany
2 Ana Trujillo México D.F. Mexico
3 Antonio Moreno México D.F. Mexico
4 Thomas Hardy London UK
5 Christina Berglund Luleå Sweden
6 Hanna Moos Mannheim Germany
7 Frédérique Citeaux Strasbourg France

 


Problem: List all orders that not between $50 and $15000

  1. SELECT Id, OrderDate, CustomerId, TotalAmount
  2. FROM [Order]
  3. WHERE NOT (TotalAmount >= 50 AND TotalAmount <= 15000)
  4. ORDER BY TotalAmount DESC

Results: 16 records.

Id OrderDate CustomerId TotalAmount
618 2/2/2014 12:00:00 AM 63 17250.00
783 4/17/2014 12:00:00 AM 71 16321.90
734 3/27/2014 12:00:00 AM 34 15810.00
175 1/22/2013 12:00:00 AM 27 49.80
24 8/1/2012 12:00:00 AM 75 48.00

“SQL WHERE AND, OR, NOT Clause”의 45개의 댓글

  1. 핑백: festival mix 2021

  2. 핑백: ตู้แปลภาษา

  3. 핑백: resource

  4. 핑백: locator spectrum

  5. 핑백: Azure DevOps

  6. 핑백: nằm mơ thấy phật bà quan âm

  7. 핑백: mơ thấy nhẫn vàng đánh con gì

  8. 핑백: mơ cãi nhau đánh con gì

  9. 핑백: nằm mơ thấy hôn môi

  10. 핑백: FSU cornhole boards

  11. 핑백: mơ thấy hoa sen

  12. 핑백: nằm mơ thấy tắm sông

  13. 핑백: buy oxycontin online paypal

  14. 핑백: dewaqq

  15. 핑백: 二手車

  16. 핑백: 메이저토토사이트

  17. 핑백: Local 365

  18. 핑백: kardinal stick

  19. 핑백: USA online gun broker

  20. 핑백: sex assignment at birth definition

  21. 핑백: 메이저토토

  22. 핑백: bulk prizes

  23. 핑백: buy morphine online

  24. 핑백: Dark0de Market Link

  25. 핑백: Darkode Market Link

  26. 핑백: UNICVV

  27. 핑백: world market darknet link

  28. 핑백: Car Parts

  29. 핑백: http://www.fakewatches.me/

  30. 핑백: https://www.bothdrop.com/

  31. I’m amazed, I have to admit. Seldom do I come across a blog that’s both educative and entertaining, and let me

    스피드바카라

    tell you, you’ve hit the nail on the head. The issue is something which too few people are speaking intelligently about. I am very happy that I came across this in my search for something relating to this.

  32. 핑백: W88casino.net

  33. Hi are using WordPress for your site pla

    바카라

    tform? I’m new to the blog world but I’m trying to get s
    tarted and create my own. Do you need any coding expertise to make your own blog? Any help would be really appreciated!|

  34. 핑백: thai-sagame

  35. I?m amazed, I have to claim. Truly rarely do I come across a blog that?s both educative as well as amusing, and also let me inform you, you have actual스피드바카라
    ly hit the nail on the head. Your suggestion is exceptional; the concern is something that not nearly enough individuals are speaking smartly about. I am very happy that I came across this in my look for something connecting to this.

  36. 핑백: fresh dumps

  37. After study a few of the post on your site currently, as well as I genuinely like your way of blogging. I bookmarked it to my book marking internet sit토토
    e listing and also will be inspecting back quickly. Pls take a look at my internet site also and also let me understand what you assume.

  38. 핑백: espiar whatsapp

  39. I?m amazed, I have to claim. Truly rarely do I come across a blog that?s both educative as well as amusing, and also let me inform you, you have a

    온라인카지노
    ctually hit the nail on the head. Your suggestion is exceptional; the concern is something that not nearly enough individuals are speaking smartly about. I am very happy that I came across this in my look for something connecting to this.

답글 남기기