我和一个朋友正在JOIN研究MySQL中提供的子句。这是我们拥有的表结构:
JOIN
create table abc ( c1 int, c2 char(1) ); create table xyz ( c2 char(1), c3 varchar(5) );
插入其中的值是:
insert into abc values (1,"a"), (2,"b"); insert into xyz values ("a","apple"), ("c","car");
现在,我有以下两个SQL语句(sqlfiddle link):
select *, 'full' from abc full join xyz using (c2);
和
select *, 'full' from abc full join xyz on abc.c2 = xyz.c2;
从小提琴中可以看出,第一个查询返回:
| C2 | C1 | C3 | FULL | |----|----|-------|------| | a | 1 | apple | full |
同时,第二个查询引发并错误:
Unknown column 'abc.c2' in 'on clause':
为什么abc.c2在使用语法ON子句时无法识别该列JOIN?
abc.c2
ON
FULL JOINMySQL不支持。这是因为full被识别为abc表的别名。试试这个查询,它运行没有错误:
FULL JOIN
full
abc
select *, 'full' from abc full join xyz on full.c2 = xyz.c2;