This Oracle tutorial explains how to use the Oracle AND condition with syntax and examples.
The Oracle AND condition (also called the AND Operator) is used to test for two or more conditions in a SELECT, INSERT, UPDATE, or DELETE statement.
The syntax for the AND Condition in Oracle/PLSQL is:
All of the conditions that must be met for the records to be selected.
The first Oracle AND condition query involves a SELECT statement with 2 conditions.
For example:
This Oracle AND example would return all customers that reside in the state of Florida and have a customer_id > 5000. Because the * is used in the SELECT statement, all fields from the customers table would appear in the result set.
Our next Oracle AND example shows how the AND condition can be used to join multiple tables in a SELECT statement.
For example:
Though the above SQL works just fine, you would more traditionally write this SQL as follows using a proper INNER JOIN.
For example:
This Oracle AND condition example would return all rows where the supplier_name is GCP. And the suppliers and orders tables are joined on supplier_id. You will notice that all of the fields are prefixed with the table names (ie: orders.order_id). This is required to eliminate any ambiguity as to which field is being referenced; as the same field name can exist in both the suppliers and the orders tables.
In this case, the result set would only display the order_id and supplier_name fields (as listed in the first part of the SELECT statement.).
This next Oracle AND example demonstrates how the AND condition can be used in the INSERT statement.
For example:
This Oracle AND condition example would insert into the suppliers table, all customer_id and customer_name records from the customers table whose customer_name is GCP and have a customer_id less than or equal to 1000.
This Oracle AND condition example shows how the AND condition can be used in the UPDATE statement.
For example:
This Oracle AND condition example would update all supplier_name values in the suppliers table to Apple where the supplier_name was RIM and had 8 offices.
Finally, this last Oracle AND example demonstrates how the AND condition can be used in the DELETE statement.
For example:
This Oracle AND condition example would delete all records from the suppliers table whose supplier_name was Apple and product was iPod.
Learn more about joining tables in Oracle.