笛卡尔积,适用情景:比如多种颜色和型号的各种组合。
1.use sql_store;
select *
from customers c
cross join products p
这里customers和products各有10条记录,因此我们的结果显示100条
把products改为orders表,这里的列,会把重复的也加上,比如可能有两个一样的customer_id
2,选择其中两列,合计100条记录
use sql_store;
select
c.first_name as customer,
p.name as product
from customers c
cross join products p
order by c.first_name
也可以用隐式语法:
use sql_store;
select
c.first_name as customer,
p.name as product
from customers c, products p
order by c.first_name
练习:
答案:
implicit syntax:
use sql_store;
select *
from shippers sh, products p
expicit syntax:
use sql_store;
select *
from shippers sh
cross join products p