All for Joomla All for Webmasters

SQL AND

The SQL AND condition is used in SQL query to create two or more conditions to be met.

It is used in SQL SELECT, INSERT, UPDATE and DELETE statements.

Let’s see the syntax for SQL AND:

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

The SQL AND condition requires that both conditions should be met.

The SQL AND condition also can be used to join multiple tables in a SQL statement.

SQL “AND” example with “INSERT” statement

This is how an SQL “AND” condition can be used in the SQL INSERT statement.

For example:

  1. INSERT INTO suppliers
  2. (supplier_id, supplier_name)
  3. SELECT account_no, name
  4. FROM customers
  5. WHERE customer_name =‘IBM’
  6. AND employees =1000;

SQL “AND” example with “UPDATE” statement

This is how the “AND” condition can be used in the SQL UPDATE statement.

For example:

  1. UPDATE suppliers
  2. SET supplier_name = ‘HP’
  3. WHERE supplier_name = ‘IBM’
  4. AND offices = 8;

SQL “AND” example with “DELETE” statement

This is how an SQL “AND” condition can be used in the SQL DELETE statement.

For example:

  1. DELETE FROM suppliers
  2. WHERE supplier_name = ‘IBM’
  3. AND product = ‘PC computers’;
PinIt
submit to reddit

Leave a Reply

Top