22,209
社区成员
发帖
与我相关
我的任务
分享
Project_ID(Key) Product_ID Designer
1 1(汽车) Wang
2 1(汽车) Zhang
Project_Detail_ID(Key) Project_ID Component_ID Draft(图纸)
1 1(Wang对汽车的改进方案) 1(汽车/发动机) XX
2 1(Wang对汽车的改进方案) 2(汽车/悬挂系统) XX
最好贴数据与结果...
lz可以 查查join的用法
---------------------------------
-- Author: Beirut(贝鲁特)
-- Comment:小爱
-- Date : 2009-08-04 18:49:08
---------------------------------
--一个三表连接的例子,你看看
create table Tag (id int ,name varchar(20), parent int)
insert into tag values(1, 'SQL', 0)
insert into tag values(2, 'MS', 1)
insert into tag values(3, 'oracle', 1)
create table Article (id int ,title varchar(20))
insert into Article values (1, 'SQL how to')
insert into Article values (2, 'reference')
create table Tag_Article (tag_id int, article_id int)
insert into Tag_Article values(2, 1)
insert into Tag_Article values(3, 2)
--id title tag_id tag_name
select a.id ,b.title,c.tag_id,c.article_id
from tag as a
inner join Article b on a.id=b.id
inner join Tag_Article c on b.id=c. article_id
/*id title tag_id article_id
----------- -------------------- ----------- -----------
1 SQL how to 2 1
2 reference 3 2
(2 行受影响)
*/
select *
from a join b on a.product_id=b.product_id
join c on b.product_id=c.product_id
join d on b.Component_ID=d.Component_ID