表A:ID=1
表B:ID=2
表C:ID=3
表D要求是使用多表查询 把表A里ID=1的值,表B里ID=2的值和表C里ID=3的值查出 并存储到表D里。
当时面试的时候一紧张...连join都不会了。
希望各位大侠给一个比较优化的答案......

解决方案 »

  1.   

    insert into d(id) 
    select id from a where id=1
    union all
    select id from b where id=2
    union all
    select id from c where id=3
      

  2.   

    不需要JOIN吧
    insert into d(id) 
    select id from a where id=1
    union all
    select id from b where id=2
    union all
    select id from c where id=3
      

  3.   

    select a.id,b.id,c.id
    from 表A  ainner join 表B b
    on a.id = b.idinner join 表C c
    on b.id = c.id
      

  4.   

    insert into d(id)
    select id from a where id=1 
    union all
    select id from b where id=2
    union all
    select id from c where id=3 
      

  5.   

    SQL code
    insert into d(id) 
    select id from a where id=1
    union all
    select id from b where id=2
    union all
    select id from c where id=3