返回结果:
Name
Product
Hansen, Ola
Printer
Svendson, Tove
?
Svendson, Stephen
Table
Svendson, Stephen
Chair
Pettersen, Kari
?
解释:
?????? LEFT JOIN返回” first_table”中所有的行尽管在”second_table”中没有相匹配的数据。
RIGHT JOIN的语法:
SELECT field1, field2, field3
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield
用”Employees”表去右外联结”Orders”表去找出相关数据:
SELECT Employees.Name, Orders.Product
FROM Employees
RIGHT JOIN Orders
ON Employees.ID = Orders.ID
返回结果:
Name
Product
Hansen, Ola
Printer
Svendson, Stephen
Table
Svendson, Stephen
Chair
解释:
?????? RIGHT JOIN返回” second_table”中所有的行尽管在”first_table”中没有相匹配的数据。
Alias
用途:
可用在表、结果集或者列上,为它们取一个逻辑名称
语法:
给列取别名:
SELECT column AS column_alias FROM table
?????? 给表取别名:
SELECT column FROM table AS table_alias
例:
“Persons”表中的原始数据:
LastName
FirstName
Address
City
Hansen
Ola
Timoteivn 10
Sandnes
Svendson
Tove
Borgvn 23
Sandnes
Pettersen
Kari
Storgt 20
Stavanger
运行下面的SQL:
SELECT LastName AS Family, FirstName AS Name FROM Persons
返回结果:
Family
Name
Hansen
Ola
Svendson
Tove
Pettersen
Kari
运行下面的SQL:
SELECT LastName, FirstName FROM Persons AS Employees
返回结果:
Employees中的数据有:
LastName
FirstName
Hansen
Ola
Svendson
Tove
Pettersen
Kari
Insert Into
用途:
?????? 在表中插入新行
语法:
?????? 插入一行数据
INSERT INTO table_name VALUES (value1, value2,....)
?????? 插入一行数据在指定的字段上
INSERT INTO table_name (column1, column2,...) VALUES (value1, value2,....)??
例:
“Persons”表中的原始数据:
LastName
FirstName
Address
City
Pettersen
Kari
Storgt 20
Stavanger
运行下面的SQL插入一行数据:
INSERT INTO Persons VALUES ('Hetland', 'Camilla', 'Hagabakka 24', 'Sandnes')
插入后”Persons”表中的数据为:
LastName
FirstName
Address
City
Pettersen
Kari
Storgt 20
Stavanger
Hetland
Camilla
Hagabakka 24
Sandnes
运行下面的SQL插入一行数据在指定的字段上:
INSERT INTO Persons (LastName, Address) VALUES ('Rasmussen', 'Storgt 67')
插入后”Persons”表中的数据为:
LastName
FirstName
Address
City
Pettersen
Kari
Storgt 20
Stavanger
Hetland
Camilla
Hagabakka 24
Sandnes
Rasmussen
?