内连接 select a.field1,b.field2 from a join b on a.id=b.id,只有a,b中id相同的记录才出现 左连接: select a.field1,b.field2 from a left join b on a.id=b.id,只要a中存在的的记录都出现。如果a中存在,b中不存在,出现的结果中b表中的字段显示为null 右连接,全连接依次类推。
例如: table1 table2 id desc id chinese 1 one 1 一 2 two 2 二 3 three 3 三 4 four 4 四 则: select a.desc, b.chinese from table1 a, table2 b where a.id = b.id; 结果就是: desc chinese one 一 two 二 three 三 four 四
左连接: select a.field1,b.field2 from a left join b on a.id=b.id,只要a中存在的的记录都出现。如果a中存在,b中不存在,出现的结果中b表中的字段显示为null
右连接,全连接依次类推。
table1 table2
id desc id chinese
1 one 1 一
2 two 2 二
3 three 3 三
4 four 4 四
则:
select a.desc, b.chinese from table1 a, table2 b where a.id = b.id;
结果就是:
desc chinese
one 一
two 二
three 三
four 四
一个表有主健,一个表有外建的那种,
from 关系名
where 主键=外键