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

Comments (75)

  1. Pingback: festival mix 2021

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

  3. Pingback: resource

  4. Pingback: locator spectrum

  5. Pingback: Azure DevOps

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

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

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

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

  10. Pingback: FSU cornhole boards

  11. Pingback: mơ thấy hoa sen

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

  13. Pingback: buy oxycontin online paypal

  14. Pingback: dewaqq

  15. Pingback: 二手車

  16. Pingback: 메이저토토사이트

  17. Pingback: Local 365

  18. Pingback: kardinal stick

  19. Pingback: USA online gun broker

  20. Pingback: sex assignment at birth definition

  21. Pingback: 메이저토토

  22. Pingback: bulk prizes

  23. Pingback: buy morphine online

  24. Pingback: Dark0de Market Link

  25. Pingback: Darkode Market Link

  26. Pingback: UNICVV

  27. Pingback: world market darknet link

  28. Pingback: Car Parts

  29. Pingback: http://www.fakewatches.me/

  30. Pingback: 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. Pingback: 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. Pingback: 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. Pingback: 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. Pingback: 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.

  40. 응답

    It’s perfect time to make some plans for the long run and it’s time to be happy.
    I have read this put up and if I may I wish to counsel you few fascinating issues or
    advice. Perhaps you

    안전놀이터 could write next articles referring to this
    article. I desire to read even more things about

  41. 응답

    Great – I should definitely pronounce, impressed with your website. I had no trouble 아바타바카라
    navigating through all tabs as well as related information ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Quite unusual. Is likely to appreciate it for those who add forums or something, site theme . a tones way for your client to communicate. Excellent task.

  42. 응답

    Great – I should definitely pronounce, impressed with your website. I had no trouble navigating through all tabs as well as related information ended up being truly easy to do to access. I recently found what I hoped for before you know it in the least. Quite unusual. Is likely to appreciate it for those who add forums or som아바타바카라
    ething, site theme . a tones way for your client to communicate. Excellent task.

  43. 응답

    It’s amazing to pay a quick visit this web site and reading the views of all
    colleagues on the topic of this article, while I am also
    zealous of getting know-how.

  44. 응답

    Please let me know if you’re looking for a article author for your
    site. You have some really great posts and I think I would be
    a good asset. If you ever want to take some of the load off,
    I’d love to write some articles for your blog in exchange for a link back to mine.
    Please send me an e-mail if interested. Regards!

  45. 응답

    Sweet blog! I found it while surfing around on Yahoo News.
    Do you have any tips on how to get listed in Yahoo News?
    I’ve been trying for a while but I never seem to get there!
    Many thanks

  46. 응답

    An outstanding share! I’ve just forwarded this onto a colleague who had been doing a little homework
    on this. And he actually bought me breakfast due to the fact that I stumbled upon it for him…
    lol. So allow me to reword this…. Thank YOU for the meal!!

    But yeah, thanks for spending the time to talk about this topic here on your internet site.
    asmr https://app.gumroad.com/asmr2021/p/best-asmr-online asmr

  47. 응답

    Thank you for another great post. Where else may just anybody get that kind of information in such a perfect manner of writing? I’ve a presentation next week, and I am at the search for such information.

  48. 응답

    I am extremely inspired together with your writing talents as neatly as with the
    structure on your weblog. Is that this a paid subject
    matter or did you modify it your self? Either way
    stay up the excellent high quality writing, it is uncommon to look a great weblog like this one nowadays..

    quest bars http://j.mp/3jZgEA2 quest bars

  49. 응답

    Today, I went to the beachfront with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She put the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear. She never wants to go back!
    LoL I know this is completely off topic but
    I had to tell someone! scoliosis surgery https://0401mm.tumblr.com/ scoliosis
    surgery

  50. 응답

    I do agree with all of the ideas you’ve presented in your post. They’re very convincing and will definitely work. Still, the posts are very short for starters. Could you please extend them a bit from next time? Thanks for the post.

  51. 응답

    Hey there! Do you use Twitter? I’d like to follow you if that would be ok. I’m definitely enjoying your blog and look forward to new updates.

Leave a comment

이메일 주소는 공개되지 않습니다.