python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
3rd highest salary in sql server

SQL WHERE AND, OR, NOT Clause [SQL Operators]

The SQL “NOT” clause is used with “WHERE” conditions.

The AND”, “OR” and “NOT” operators are used to test two or more conditions in a SELECT, INSERT, UPDATE, or DELETE statements.

The “WHERE” clause with “AND” operator requires that two conditions are true and an “OR” requires that one of two conditions is true and the “NOT” negates the specified condition.


Syntax:-

--THE WHERE WITH AND OPERATOR 
SELECT ColumnName, ColumnName
  FROM TableName  WHERE Condition1 AND Condition2

--THE WHERE WITH OR OPERATOR
UPDATE TableName
   SET ColumnName = value
WHERE Condition1 OR Condition2

--THE WHERE WITH NOT OPERATOR
DELETE TableName
WHERE NOT Condition1


Examples:-
--SELECT ALL COUNTRIES
SELECT [Id]
      ,[CountryName]
      ,[CountryCode]
  FROM [test].[dbo].[Countries]

Result:-
Id CountryName CountryCode
-------------------------------------
1 India         IN
2 Nepal         NP
3 USA         US
4 Rasia         NULL
5 Australia AUS

Example :-
-- SELECT ALL MATCHED CONDITIONS COUNTRIES
SELECT [Id]
      ,[CountryName]
      ,[CountryCode]
  FROM [test].[dbo].[Countries]
  WHERE (CountryCode = 'IN' AND Id <> 2) OR  (CountryCode = 'US' AND Id <> 2)

Result :-
Id CountryName CountryCode
-----------------------------------
1 India         IN
3 USA         US

Stayed Informed SQL Server Query and Examples

I hope you are enjoying with this post! Please share with you friends. Thank you!!
ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions