我有两个表,表1:
ID,手柄ID,盖子ID。
表2:
ID,FullName 表1里的手柄ID和盖子ID都是对应表2的ID 那我现在要选出表1的记录,要显示的是表1ID,手柄FULLNAME,盖子FULLNAME我举例说吧
表1有记录1个如下:
ID      HANDID           LIDID
1       1                2
表2有两记录:
ID        FULLNAME
1         小手柄
2         小盖子那我要的结果是
1   小手柄   小盖子

解决方案 »

  1.   

    select 表1.id,表2.FULLNAME from 表1 join 表2 on 表1.手柄ID=表2.ID  OR  表1.盖子ID=表2.ID
      

  2.   

    不会吧,他直接说from子句语法错误
      

  3.   

    select 表1.id,(select fullname from 表2 where id=handid) '手柄fullname',
    (select fullname from 表2 where id=lidid)'盖子fullname' from 表1
      

  4.   

    select tb1.id,tb2.fullname,tb3.fullname
    from tb1,tb2,tb2 tb3
    where tb1.handid=tb2.id and tb1.lidid=tb3.id
      

  5.   

    select *
    from (表1 inner join 表2 on 表1.手柄ID=表2.id)          inner join 表2 on 表1.盖子ID=表2.id
      

  6.   

    create table #s1(id char,col1 char,col2 char)create table #s2(id char,col1 text)insert into #s1 values('1','1','2')insert into #s2 values('1','手柄')
    insert into #s2 values('2','盖子')select #s1.id,#s2.col1,#s3.col1 from(#s1 inner join #s2 on #s1.col1=#s2.id) inner join #s2 as #s3 on #s1.col2=#s3.id
    输出结果1,手柄,盖子
      

  7.   

    select a.id,(select b.fullname from tablename2 b where b.id=a.HANDID) as handid,(select c.fullname from tablename2 c where c.id=a.LIDID) as lidid from tablename1 a测试通过!