Oracle/PLSQL: WHERE Clause

SQL: WHERE Clause

The SQL WHERE clause allows you to filter the results from an SQL statement - SQL SELECT statementSQL INSERT statementSQL UPDATE statement, or SQL DELETE statement.

It is difficult to explain the syntax for the SQL WHERE clause, so instead, we'll take a look at some examples.

SQL WHERE Clause - Single condition example

SELECT *
FROM suppliers
WHERE supplier_name = 'IBM';

In this SQL Where clause example, we've used the SQL WHERE clause to filter our results from the suppliers table. The SQL statement above would return all rows from the suppliers table where the supplier_name is IBM. Because the * is used in the select, all fields from the suppliers table would appear in the result set.

SQL WHERE Clause - Using SQL "AND" condition example

SELECT *
FROM suppliers
WHERE supplier_city = 'Chicago'
and supplier_id > 1000;

This SQL Where clause example uses the WHERE clause to define multiple conditions. In this case, this SQL statement uses the SQL "AND" Condition to return all suppliers that are located in Chicago and whose supplier_id is greater than 1000.

SQL WHERE Clause - Using SQL "OR" condition example

SELECT supplier_id
FROM suppliers
WHERE supplier_name = 'IBM'
or supplier_name = 'Apple';

This SQL Where clause example uses the WHERE clause to define multiple conditions, but instead of using the SQL "AND" Condition, it uses the SQL "OR" Condition. In this case, this SQL statement would return all supplier_id values where the supplier_name is IBM or Apple.

SQL WHERE Clause - Joining Tables example

SELECT suppliers.suppler_name, orders.order_id
FROM suppliers, orders
WHERE suppliers.supplier_id = orders.supplier_id
and suppliers.supplier_city = 'Atlantic City';

This SQL Where clause example uses the SQL WHERE clause to join multiple tables together in a single SQL statement. This SQL statement would return all supplier names and order_ids where there is a matching record in the suppliers and orders tables based on supplier_id, and where the supplier_city is Atlantic City.

Learn more about SQL joins.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值