聘我网

新概念招聘3.0

sql 查询问题

vote up0vote downstar

我有三个表:

table1 id a1 a2 a3 a4 数据略

table2 id b1 b2 b3 b4 数据略

table3 id table2_id  table1_id
       1     1         4
       2     1         6 
       3     1         2
       4     2         1
       5     2         7

我要在表三里查询出table2id为1的所有的table1id 数据,然后查table1里所对应的数据,然后输出出来,这个sql该怎么写呀

 
是MySQL还是? - Shore 2009-11-23, 04:25
MySQL - nightwindw 2009-11-23, 04:26

1 个答复

vote up0vote downcheck

试试看:

select table1.* from table1 left join table3 on table1.id=table3.table1_id where table3.table2_id=1

更新

如果要去重:

select distinct table1.* from table1 left join table3 on table1.id=table3.table1_id where table3.table2_id=1
链接
哇,你真强啊!!!!我服! - nightwindw 2009-11-23, 04:29
shore 我发现你写的函数不对。 - nightwindw 2009-11-26, 02:42
如果还要把table3里面的ID号一起查出来,怎么写呀? - nightwindw 2009-11-26, 03:42
,table3.id id3加到table1.*后面 - Shore 2009-11-26, 03:59

您的回答





不是您要找的问题? 浏览其他含有标签 的问题或者 自己问个.