SQL AND, OR and NOT Operators

SQL AND, OR and NOT operators are used to combine and test multiple conditions for data in SQL. AND, OR and NOT operators can combine with WHERE clauses.

The AND Operator:
AND Operator display records if all the condition separated by AND evaluates to be true.

AND Operator Syntax :

The syntax of the AND Operator is −

SELECT column1, column2, columnN 
FROM table_name
WHERE [condition1] AND [condition2]...AND [conditionN];



The OR Operator:

OR Operator display records if any one of the condition separated by OR evaluates to be true.



OR Operator Syntax :

The syntax of the OR Operator is −

SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2... OR conditionN;



The NOT Operator:

NOT Operator display records if the condition evaluates to be not true.



NOT Operator Syntax :

The syntax of the NOT Operator is −

SELECT column1, column2, ...
FROM table_name
WHERE NOT condition;



AND, OR and NOT Operator Example :

Consider the Customer table with the following records -

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
4 Muhammad 24 Udaipur 50000
5 Sai 30 Mumbai 27000


AND Example:- The following code is an example, which would fetch the all fields from Customer table where Address is Udaipur AND Age is 24 (means both the condition must be true).

SELECT * FROM Customer
WHERE Address='Udaipur' AND Age=24;


The result for the respective sql query is as follows −

CustomerID CustomerName Age Address CustomerSalary
4 Muhammad 24 Udaipur 50000



OR Example:- The following code is an example, which would fetch the all fields from Customer table where Address is Udaipur OR Age is 24 (means any one of the condition must be true).

SELECT * FROM Customer
WHERE Address='Udaipur' OR Age=24;


The result for the respective sql query is as follows −

CustomerID CustomerName Age Address CustomerSalary
1 Aarav 28 Udaipur 28000
4 Muhammad 24 Udaipur 50000



NOT Example:- The following code is an example, which would fetch the all fields from Customer table where Address is NOT Udaipur(means the condition must be NOT true).

SELECT * FROM Customer
WHERE NOT Address='Udaipur';


The result for the respective sql query is as follows −

CustomerID CustomerName Age Address CustomerSalary
2 Vivaan 25 Mumbai 30000
3 Reyansh 28 Chennai 35000
5 Sai 30 Mumbai 27000



Visit :


Discussion



* You must be logged in to add comment.

pHqghUme
555

pHqghUme
555

pHqghUme
555

pHqghUme
-1 OR 2+637-637-1=0+0+0+1 --

pHqghUme
-1 OR 3+637-637-1=0+0+0+1 --

pHqghUme
-1 OR 3*2<(0+5+637-637) --

pHqghUme
-1 OR 3*2>(0+5+637-637) --

pHqghUme
-1 OR 2+29-29-1=0+0+0+1

pHqghUme
-1 OR 3+29-29-1=0+0+0+1

pHqghUme
-1 OR 3*2<(0+5+29-29)

pHqghUme
-1 OR 3*2>(0+5+29-29)

pHqghUme
-1' OR 2+249-249-1=0+0+0+1 --

pHqghUme
-1' OR 3+249-249-1=0+0+0+1 --

pHqghUme
-1' OR 3*2<(0+5+249-249) --

pHqghUme
-1' OR 3*2>(0+5+249-249) --

pHqghUme
-1' OR 2+828-828-1=0+0+0+1 or 'Uk1ja3Or'='

pHqghUme
-1' OR 3+828-828-1=0+0+0+1 or 'Uk1ja3Or'='

pHqghUme
-1' OR 3*2<(0+5+828-828) or 'Uk1ja3Or'='

pHqghUme
-1' OR 3*2>(0+5+828-828) or 'Uk1ja3Or'='

pHqghUme
-1" OR 2+403-403-1=0+0+0+1 --

pHqghUme
-1" OR 3+403-403-1=0+0+0+1 --

pHqghUme
-1" OR 3*2<(0+5+403-403) --

pHqghUme
-1" OR 3*2>(0+5+403-403) --

pHqghUme
if(now()=sysdate(),sleep(15),0)

pHqghUme
0'XOR(if(now()=sysdate(),sleep(15),0))XOR'Z

pHqghUme
0"XOR(if(now()=sysdate(),sleep(15),0))XOR"Z

pHqghUme
(select(0)from(select(sleep(15)))v)/*'+(select(0)from(select(sleep(15)))v)+'"+(select(0)from(select(sleep(15)))v)+"*/

pHqghUme
-1; waitfor delay '0:0:15' --

pHqghUme
-1); waitfor delay '0:0:15' --

pHqghUme
1 waitfor delay '0:0:15' --

pHqghUme
BDcHX9RR'; waitfor delay '0:0:15' --

pHqghUme
-5 OR 914=(SELECT 914 FROM PG_SLEEP(15))--

pHqghUme
-5) OR 957=(SELECT 957 FROM PG_SLEEP(15))--

pHqghUme
-1)) OR 884=(SELECT 884 FROM PG_SLEEP(15))--

pHqghUme
jFNG6hKZ' OR 938=(SELECT 938 FROM PG_SLEEP(15))--

pHqghUme
Ur3oCkXA') OR 666=(SELECT 666 FROM PG_SLEEP(15))--

pHqghUme
aZ22bnzi')) OR 664=(SELECT 664 FROM PG_SLEEP(15))--

pHqghUme
555*DBMS_PIPE.RECEIVE_MESSAGE(CHR(99)||CHR(99)||CHR(99),15)

pHqghUme
555'||DBMS_PIPE.RECEIVE_MESSAGE(CHR(98)||CHR(98)||CHR(98),15)||'

pHqghUme
1'"

pHqghUme

pHqghUme
@@4QjZg

pHqghUme
555

pHqghUme
555

pHqghUme
555