The FROM clause in SQL Server
The SQL Server FROM clause (T-SQL) is used to list the necessary tables in the SQL Server query.
FROM clause clause
FROM bang1
[ { INNER JOIN
| LEFT OUTER JOIN
| RIGHT OUTER JOIN
| FULL OUTER JOIN } bang2
ON bang1.cot1 = bang2.cot1 ]
Variable names and variable values
bang1 and bang2 - tables used in SQL statements. Two linked tables according to the principle of state1.cot1 = bang2.cot1.
Note
- Must have at least 1 table in the FROM clause.
- If there are 2 or more tables, these tables are usually connected by keywords INNER or OUTER. Although it is possible to connect using the old syntax in the WHERE clause, it is recommended to use the new standard with the connection rule in the FROM clause.
Example - 1 table
SELECT *
FROM nhanvien
WHERE ten = 'Jane;
This example uses the FROM clause to get the table of nhanvien
, no other connection tables.
Example - 2 tables with INNER JOIN
SELECT nhacungcap.nhacungcap_id, nhacungcap.nhacungcap_ten, donhang.donhang_ngay
FROM nhacungcap
INNER JOIN donhang
ON nhacungcap.nhacungcap_id = donhang.nhacungcap_id;
In this example, the FROM
clause gives 2 tables and donhang
, connecting these two tables with INNER JOIN
with nhacungcap_id
column on both tables.
Example - 2 tables with OUTER JOIN
SELECT nhanvien.nhanvien_id, danhba.ho
FROM nhanvien
LEFT OUTER JOIN danhba
ON nhanvien.nhanvien_id = danhba.danhba_id
WHERE nhanvien.ten = 'Sarah';
This FROM clause gives two tables, nhanvien
and danhba
, using LEFT OUTER JOIN to connect with nhanvien_id
column in both tables.
Previous article: SELECT command in SQL Server
Next lesson: Comparison operators in SQL Server
You should read it
May be interested
- SELECT command in SQL Serverthis tutorial will help you use sql server select statements (t-sql) with syntax and examples.
- Analysis services in MS SQL Serverthis service is used to analyze a large amount of data and for businesses to make decisions.
- Integrated services in MS SQL Serverintegrated services are used to implement etl (extraction, transform and load data) and administrator jobs.
- Execution Plans - Execution plan in MS SQL Serverthe execution plan is created using the query optimizer with the help of statistics, the algebrizer / process tree.
- Reporting service in MS SQL Serverthe report is a presentationable component.
- High Availability - Availability of MS SQL Serverbasically, there are 5 options to set up database availability in ms sql server.