asp.net c# Sql server 2000...
有4个表:
表1的字段是:
id 自动编号
const 内容
2id 等于表2的2id
3id 等于表3的3id
4id 等于表4的4id表2的字段是:
2id 自动编号
const2 内容表3的字段是:
3id 自动编号
const3 内容表4的字段是:
4id 自动编号
const4 内容我现在需要把表1,表2,表3,表4的const,const2,const3,const4取出来放在一张表上谢谢

解决方案 »

  1.   

    select b1.const,b2.const2,b3.const3,b4.const4 from b1 
    inner join b2 on b1.id2=b2.id2
    inner join b3 on b1.id3=b3.id3
    inner join b4 on b1.id3=b4.id4
      

  2.   

    select b1.const,b2.const2,b3.const3,b4.const4 from b1 
    inner join b2 on b1.[2id]=[b2.2id]
    inner join b3 on b1.[3id]=[b3.3id]
    inner join b4 on b1.[4id]=[b4.4id]
      

  3.   

    select const,(select const2 from 表2 where 表2.id=表1.2id) as const2,(select const3 from 表3 where 表3.id=表1.3id) as const3,(select const4 from 表4 where 表4.id=表1.4id) as const4, from 表1
      

  4.   

    这是横排
    select a.*,b.*,c.*,d.* 
    from 表1 as a
    inner join 表2 as b on a.2id= b.2id
    inner join 表3 as c on a.3id= b.2id
    inner join 表4 as d on a.4id= b.2id这是竖排
    select a.id,a.const,'表1' as Re
    from 表1 as a
    where a.id =10
    union
    select b.id,b.const,'表2' 
    from 表2 as b
    where exists(
        select 8 from 表1 as a 
           where a.2id= b.2id and a.id =10)
    union
    select c.id,c.const,'表3' 
    from 表3 as c
    where exists(
        select 8 from 表1 as a 
           where a.3id= c.3id and a.id =10)
    union
    select d.id,d.const,'表4' 
    from 表4 as d
    where exists(
        select 8 from 表1 as a 
           where a.4id= d.4id and a.id =10)
      

  5.   

    小山哥,你这样好像不行吧,我试过,也许是我哪弄错了,明天我再去弄一弄,另外,b1.[4id]=[b4.4id]不用[]吧?直接用的就了??
      

  6.   

    select [b1].[const] from [b1] 
    union all
    select [b2].[const2] from [b2] 
    union all 
    [b3].[const3] from [b3] 
    union all 
    [b4].[const4] from [b4]
      

  7.   

    select b1.const,b2.const2,b3.const3,b4.const4 from b1 
    inner join b2 on b1.[2id]=[b2.2id]
    inner join b3 on b1.[3id]=[b3.3id]
    inner join b4 on b1.[4id]=[b4.4id]这个比较好一些
      

  8.   

    横向排列
    select b1.const,b2.const2,b3.const3,b4.const4 from b1 
    inner join b2 on b1.id2=b2.id2
    inner join b3 on b1.id3=b3.id3
    inner join b4 on b1.id3=b4.id4   
    纵向排列
    select [b1].[const] from [b1] 
    union all
    select [b2].[const2] from [b2] 
    union all 
    [b3].[const3] from [b3] 
    union all 
    [b4].[const4] from [b4]
      

  9.   

    select b1.const,b2.const2,b3.const3,b4.const4 from b1 
    inner join b2 on b1.[2id]=b2.[2id]
    inner join b3 on b1.[3id]=b3.[3id]
    inner join b4 on b1.[4id]=b4.[4id]
      

  10.   

    select a.const, b.const, c.const, d.const 
    from 表1 a, 表2 b, 表3 c, 表4 d
    where a.[id] = b.[2id] and a.[id] = c.[3id] and a.[id] = d.[4id]