FROM nhanvien
WHERE ten =
'Sarah'; In this example, we set the alias for the second column (ie, combining the first and last name) as NAME. In the result, NAME will be the title of the second column. Because the above bi_danh has no spaces, no quotes are needed. But if you want, use this mark.
SELECT nhanvien_id, ten + ho AS 'NAME'
FROM nhanvien
WHERE ten = 'S
arah';
This is another example that needs to put bi_danh in quotation marks.
SELECT nhanvien_id, ten + ho AS 'TEN NHAN VIEN'
FROM nhanvien
WHERE ten = 'Sara
h';
In this example, the second column in the result is set to TEN NHAN VIEN.
For example - set the alias for the table
Setting the alias for the table can be used to list a table more than once in the FROM clause (or self-connect) or shorten the table name to make it easier to read.
SELECT s.sanpham_ten, hangtonkho.chatluong
FROM sanpham s
INNER JOIN hangtonkho
ON s.sanpham_id = hangtonkho.sanpham_id
ORDER BY s.tsanph
am_ten ASC, hangtonkho.chatluong DESC;
The above example creates an alias for the sanpham table which is s. Now in the SQL statement, it is possible to call the sanpham table s. When creating a table alias, it is not necessary to create an alias for all tables given in the FROM clause. For example, create an alias for the hangtonkho table as shown below.
SELECT s.sanpham_ten, h.chatluong
FROM sanpham s
INNER JOIN hangtonkho h
ON s.sanpham_id = h.sanpham_id
ORDER BY s.sanpham_ten ASC,
h.chatluong DESC;
The hangtonkho board is called h and the sanpham board is called s.
Previous article: Conditions NOT in SQL Server
Next lesson: JOIN in SQL Server