what is AND and OR operator in mysql.

MySQL AND Condition is used to test two or more conditions in a SELECT, INSERT, UPDATE, or DELETE statement. The MySQL AND condition requires that all of the conditions (ie: condition1, condition2, condition_n) be must be true for the record to be included in the result set.

With SELECT Statement :-

SELECT * FROM Employee WHERE state = 'Delhi' AND salary > 10000;

With INSERT Statement

INSERT INTO suppliers (supplier_id, supplier_name) SELECT employee_id, employee_name FROM employee WHERE employee_name = 'tech' AND employee_id < 100;

UPDATE Statement

UPDATE suppliers SET supplier_name = 'mahi' WHERE supplier_name = 'itechxpert' AND offices = 10;

DELETE Statement

DELETE FROM suppliers WHERE supplier_name = 'itechxpert' AND product = 'computers';


JOINING Tables

SELECT orders.order_id, suppliers.supplier_name FROM suppliers, orders WHERE suppliers.supplier_id = orders.supplier_id AND suppliers.supplier_name = 'Dell';

OR Condition

MySQL OR Condition is used to test two or more conditions where records are returned when any one of the conditions are met. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.

SELECT * FROM contacts WHERE state = 'California' OR contact_id < 1000;

example

SELECT supplier_id, supplier_name FROM suppliers WHERE supplier_name = 'Microsoft' OR state = 'Florida' OR offices > 10;

With INSERT

INSERT INTO suppliers (supplier_id, supplier_name) SELECT customer_id, customer_name FROM customers WHERE state = 'delhi' OR state = 'india';

Delete statement

DELETE FROM customers WHERE last_name = 'habi' OR first_name = 'mahi';

With update :-

UPDATE suppliers SET supplier_name = 'Apple' WHERE supplier_name = 'RIM' OR available_products > 25;

Combining the AND and OR Conditions

SELECT * FROM customers WHERE (state = 'delhi' AND last_name = 'mahi') OR (customer_id > 4500);

delete

DELETE FROM contacts WHERE state = 'delhi' AND (last_name = 'Smith' OR last_name = 'Anderson');





Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here


Ittutorial