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
- HAVING clause in SQLthe having clause in sql is used to filter records and retrieve only those records that match the requirements or are actually needed.
- Interesting Facts About The Santa Clausethe santa clause is one of the best christmas movies of all time. however, behind this christmas movie are surprising, little-known facts about the making process.
- GROUP BY command in SQLthe group by clause in sql is used in conjunction with the select statement to sort data uniformly into groups.
- ORDER BY command in SQLin sql, the order by clause is used to sort data in ascending order or in descending order on one or more columns.
- The difference between web server and app serveryou have probably seen that the terms web server and app server are often used interchangeably as if they are related to the same thing and also facilitate the website to function properly. but in reality, they are not the same.
- Network basics: Part 3 - DNS Servera dns server is a server that contains a database of public ip addresses and hostnames associated with them. in most cases, the dns server is used to resolve or translate those common names into ip addresses as required.
- Sort results in SQLto sort data in sql, we use the order by clause.
- The clause combines UNION data in SQLin sql, you can combine the same structured data from multiple tables into one query using the union and union all operators.
- How to set up your own Git server on Linuxwhile you can count on globally renowned git hosting services like github, in some cases it is better to host a personal git server for enhanced privacy, customizability, and security.
- Use IIS to set up FTP Server on Windowsset up an ftp server (file transfer protocol server) to share and convert large files with unlimited traffic.