left join 關鍵字從左表(table1)返回所有的行,即使右表(table2)中沒有匹配。如果右表中沒有匹配,則結果為 null。
sql left join 語法
select column_name(s)
from table1
left join table2
on table1.column_name=table2.column_name;
或:
select column_name(s)
from table1
left outer join table2
on table1.column_name=table2.column_name;
注釋:在某些資料庫中,left join 稱為 left outer join。
select customers.customername, orders.orderid
from customers
left join orders
on customers.customerid=orders.customerid
order by customers.customername;
注釋:left join 關鍵字從左表(customers)返回所有的行,即使右表(orders)中沒有匹配。
right join 關鍵字從右表(table2)返回所有的行,即使左表(table1)中沒有匹配。如果左表中沒有匹配,則結果為 null。
sql right join 語法
select column_name(s)
from table1
right join table2
on table1.column_name=table2.column_name;
或:
select column_name(s)
from table1
right outer join table2
on table1.column_name=table2.column_name;
注釋:在某些資料庫中,right join 稱為 right outer join。
select orders.orderid, employees.firstname
from orders
right join employees
on orders.employeeid=employees.employeeid
order by orders.orderid;
注釋:right join 關鍵字從右表(employees)返回所有的行,即使左表(orders)中沒有匹配。
full outer join 關鍵字只要左表(table1)和右表(table2)其中乙個表中存在匹配,則返回行.
full outer join 關鍵字結合了 left join 和 right join 的結果。
sql full outer join 語法
select column_name(s)
from table1
full outer join table2
on table1.column_name=table2.column_name;
:
獲取更多的資訊
摘要 資料庫 ClickHouse DDL
create database if not exists db name on cluster cluster create table if not exists db.table name on cluster cluster name1 type1 default materialized ...
資料庫摘要 5 Sql IN
in 操作符允許您在 where 子句中查詢多個值。select column name s from table name where column name in value1,value2,使用northwind樣本資料庫 select from customers where city in...
資料庫摘要 6 Sql Inner
inner join 關鍵字在表中存在至少乙個匹配時返回行。sql inner join 語法 select column name s from table1 inner join table2 on table1.column name table2.column name 或 select c...