一道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                                            [email protected]
1           zy                                                 male                                               1           American                                           [email protected]
2           zk                                                 male                                               2           beijing                                            [email protected]
2           zk                                                 male                                               2           nanjing                                            [email protected]

(4 row(s) affected) 

 问题,如果在left join语句中只取出与附表第一条记录联合的结果如何做?即主表数据只和附表第一条联合,其余忽略,例如下列结果:
id          name                                               sex                                                id          address                                            email
----------- -------------------------------------------------- -------------------------------------------------- ----------- -------------------------------------------------- ---------------
1           zy                                                 male                                               1           beijing                                            [email protected]
2           zk                                                 male                                               2           beijing                                            [email protected]



 

posted @ 2009-08-19 15:13  zyip  阅读(1562)  评论(29)    收藏  举报