SQL有SQL92与SQL99两个重要的标准版本,两个版本中的连接查询方式不太相同。在平常写的过程中容易混淆。

  1. 笛卡尔积:
from a,b 
# 等同于 
from a cross join b
  1. 等值连接:
from a,b where a.f1=b.f1 
# 等同于
from a join b on a.f1=b.f1 
  1. 自然连接:
from a,b where a.f1=b.f1 and a.f2=b.f2
# 等同于:
from a cross join b
	注意:	nutural join 会把进行连接的两个表中相同的字段 进行等值连接
  1. USING:
from a,b where a.f1=b.f1 and a.f2=b.f2
# 等同于:
from a join b using (f1,f2)
注意:join与natural不同在于,不会把所有字段都进行等值连接,而是根据using后面指定定的字段。且必须是from a join b using()格式,不能是 from a,b using()
所为xy
原创文章 59获赞 8访问量 2527
关注私信
展开阅读全文