AND condition / OR condition.
Oracle / sqlserver we use AND / OR condition in below statement
SELECT, INSERT, UPDATE, or DELETE statement. while any operation on the table both condition check the perform the actions.
Syntax
select * from <table_name>
WHERE <condition 1>
AND <condition 2>
OR condition;
For example of AND / OR condition -
SELECT *
FROM customer_master
WHERE (Name = 'John' AND dept_id = '10')
OR (customer_id < 10);
we can user multiple or conditions as below , in sql we check the multiple conditions using "AND" "OR"
SELECT Customer_id
FROM customer_master
WHERE (customer_id >= 10)
OR (STATE = 'BIHAR' AND state = 'DELHI')
OR (JOIN_DATE >= '10-JUN-2010' AND customer_name like 'John%');
when we insert some data using single or multiple table and condition and OR condition is very important.
Example-
INSERT INTO customer_master
(customer_id, customer_name)
SELECT cust_id, cust_name
FROM customers
WHERE (customer_name = 'John' OR state = 'BIHAR')
AND customer_id > 10;
when we update any table using UPDATE Statement the conditions is very important
Example:
UPDATE customer_master
SET state = 'DELHI'
WHERE customer_name = 'John'
AND (state = 'BIHAR' OR state = 'MAHARASHTRA');
In delete statement condition is very important while delete the records , if we exclude the condition all table will deleted.
Example-
DELETE FROM customer_master
WHERE state = 'BIHAR'
AND (DEPT_ID >= 10 OR customer_name = 'John');
Note: the best practice is to use AND condition AND OR condition in sql query when you are doing any Statement like Insert,update and delete.
ConversionConversion EmoticonEmoticon