The SQL FROM clause is used to list the tables and any joins required for the SQL statement.
SQL: FROM Clause
The SQL FROM clause is used to list the tables and any joins required for the SQL statement.
Syntax
The syntax for the FROM Clause in SQL is:
FROM table1 [ { INNER JOIN | LEFT [OUTER] JOIN | RIGHT [OUTER] JOIN | FULL [OUTER] JOIN } table2 ON table1.column1 = table2.column1 ]
Parameters or Arguments
table1 and table2
These are the tables used in the SQL statement. The two tables are joined based on table1.column1 = table2.column1.
Note;
- When using the FROM clause in a SQL statement, there must be at least one table listed in the FROM clause.
- If there are two or more tables listed in the SQL FROM clause, these tables are generally joined using INNER or OUTER joins.
Example - One Table Listed in the FROM Clause
We'll start by looking at how to use the FROM clause that lists only a single table in the SQL statement.
In this example, we have a table called suppliers with the following data:
supplier_id | supplier_name | city | state |
---|---|---|---|
100 | Microsoft | Redmond | Washington |
200 | Mountain View | California | |
300 | Oracle | Redwood City | California |
400 | Kimberly-Clark | Irving | Texas |
500 | Tyson Foods | Springdale | Arkansas |
600 | SC Johnson | Racine | Wisconsin |
700 | Dole Food Company | Westlake Village | California |
800 | Flowers Foods | Thomasville | Georgia |
900 | Electronic Arts | Redwood City | California |
Enter the following SQL statement:
SELECT * FROM suppliers WHERE supplier_id < 400 ORDER BY city DESC;
There will be 3 records selected. These are the results that you should see:
supplier_id | supplier_name | city | state |
---|---|---|---|
300 | Oracle | Redwood City | California |
100 | Microsoft | Redmond | Washington |
200 | Mountain View | California |
0 Comments