大家看看,这种写法的连接,属于哪种类型的连接呀?
--------------------------------
就是下面这种写法:select *
from t1 a,t2 b
where a.id=b.id
连接有多种,我不知这是哪一种,是 inner join 还是 left join 或是别的
是下面的哪一种,或是哪种都不是
--第一种:
select *
from t1 a inner join t2 b
on (a.id=b.id)--第二种:
select *
from t1 a left join t2 b
on (a.id=b.id)
--------------------------------
就是下面这种写法:select *
from t1 a,t2 b
where a.id=b.id
连接有多种,我不知这是哪一种,是 inner join 还是 left join 或是别的
是下面的哪一种,或是哪种都不是
--第一种:
select *
from t1 a inner join t2 b
on (a.id=b.id)--第二种:
select *
from t1 a left join t2 b
on (a.id=b.id)
from t1 a,t2 b
where a.id=b.id
-------
内连接 只取两边匹配的行
select *
from t1 a,t2 b
where a.id=b.id应该属于第一种吧!
默认的应该是按INNER JOIN来执行的,除非指定了OUTER JOIN。
我觉得写在 on 后面,可读性更好些。
--測試
inner join
楼下的,问下这两种写法效率怎么样
-------
呵呵 我就是觉得如果N个表相连 inner join之间并没有顺序关系,然后看起来有点辛苦。你比如select a.col1,b.col3,c.col4,d.col2..,f.colx from a
inner join b on a = col1=b.col1
inner join c on b.col2=c.col2 -- row #3
inner join d on d.col6=c.col6 -- row #4
....
inner join f on f.colx=c.colx连接行可以随意换 有时候把关系反正弄混了 其实这应该是我眼睛不好的原因拉..