一道sql面试题
两个表a,b
a中字段为:id,name
b中字段为:id,email,address
查询语句:select a.*,b.* from a left join b on a.id=b.id
结果为:
id name sex id address email
----------- -------------------------------------------------- -------------------------------------------------- ----------- -------------------------------------------------- -
1 zy male 1 beijing zyip@qq.com
1 zy male 1 American zyip@msn.com
2 zk male 2 beijing zk@qq.com
2 zk male 2 nanjing zk@sina.com.cn
(4 row(s) affected)
问题,如果在left join语句中只取出与附表第一条记录联合的结果如何做?即主表数据只和附表第一条联合,其余忽略,例如下列结果:
id name sex id address email
----------- -------------------------------------------------- -------------------------------------------------- ----------- -------------------------------------------------- ---------------
1 zy male 1 beijing zyip@qq.com
2 zk male 2 beijing zk@qq.com