All for Joomla All for Webmasters

SQL OR

The SQL OR condition is used in a SQL query to create a SQL statement where records are returned when any one of the condition met. It can be used in a SELECT statement, INSERT statement, UPDATE statement or DELETE statement.

Let’s see the syntax for OR condition:

  1. SELECT columns
  2. FROM tables
  3. WHERE condition 1
  4. OR condition 2;

SQL “OR” example with SQL SELECT

  1. SELECT *
  2. FROM suppliers
  3. WHERE city = ‘New York’
  4. OR available_products >= 250;

SQL “OR” example with SQL INSERT

You can see in below example that how an SQL “OR” condition is used with SQL insert statement.

For example:

  1. INSERT INTO suppliers(supplier_id, supplier_name)
  2. SELECT account_no, name
  3. FROM customers
  4. WHERE city = ‘New Delhi’
  5. OR city = ‘Ghaziabad’;

SQL “OR” example with SQL UPDATE

For example:

  1. UPDATE suppliers
  2. SET supplier_name = ‘HP’
  3. WHERE supplier_name = ‘IBM’
  4. OR available_product >36;

SQL “OR” example with SQL DELETE

For example:

  1. DELETE FROM suppliers
  2. WHERE supplier_name = ‘IBM’
  3. OR employee <=100;
PinIt
submit to reddit

Leave a Reply

Top