ORACLE | ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
| ||||||||
|
Oracle - From Clause
FROM clause is a mandatory clause in SELECT expression. It specifies the tables from which data is to be retrieved.
FROM table_name...
Expressions...
Let's take an example to explain how to use FROM clause to retrieve data from one table. Consider a table "customers".
CREATE TABLE "CUSTOMERS"
( "NAME" VARCHAR2(4000),
"AGE" NUMBER,
"SALARY" NUMBER,
"STATE" VARCHAR2(4000)
)
/
Name | Age | Salary | City |
---|---|---|---|
Seethu | 16 | 12000 | Bangalore |
Nithya | 21 | 25000 | Bangalore |
Sanvika | 26 | 56000 | Bangalore |
Pranvitha | 21 | 25000 | Hyderabad |
Sresta | 21 | 23000 | Hyderabad |
Gauri | 27 | 27000 | Hyderabad |
Danush | 31 | 31000 | Maharashtra |
Pralaynath | 65 | 76000 | Kerala |
Pranav | 56 | 87000 | Kerala |
SELECT *
FROM customers
WHERE salary >= 20000
ORDER BY salary ASC;
NAME | AGE | SALARY | CITY |
---|---|---|---|
Sresta | 21 | 23000 | Hyderabad |
Pranvitha | 21 | 25000 | Hyderabad |
Nithya | 21 | 25000 | Bangalore |
Gauri | 27 | 27000 | Hyderabad |
Danush | 31 | 31000 | Maharashtra |
Pralayanath | 65 | 76000 | Kerala |
Pranavi | 68 | 87000 | Kerala |
Let's take two tables "suppliers" and "order1".
Column_name | Datatype | Nullable | Default | Primarykey |
---|---|---|---|---|
Supplier_ID | NUMBER | yes | - | - |
Supplier_Name | VARCHAR2(4000) | yes | - | - |
Supplier_address | VARCHAR2(4000) | yes | - | - |
Supplier_ID | Supplier_Name | Supplier_Address |
---|---|---|
1 | Bata shoes | Agra |
2 | Kingfisher | Delhi |
3 | VOJO | Lucknow |
Column_name | Datatype | Nullable | Default | Primarykey |
---|---|---|---|---|
Order_Number | NUMBER | yes | - | - |
Supplier_ID | NUMBER | yes | - | - |
City | VARCHAR2(4000) | yes | - | - |
Order_Number | Supplier_ID | City |
---|---|---|
101 | 1 | Ahmedabad |
102 | 2 | Karnataka |
SELECT suppliers.supplier_id, suppliers.supplier_name, order1.order_number
FROM suppliers
INNER JOIN order1
ON suppliers.supplier_id = order1.supplier_id;
Supplier_ID | Supplier_Name | Order_number |
---|---|---|
1 | Bata Shoes | 101 |
2 | Kingfisher | 102 |