大虾们,小弟只会写简单的一些sql,现有两条sql想糅合成一条,希望大家给些提示第一条:
select  A.id  from t_item  A , t_xxx B 
where A.type =  2 and A.itemtype = 5 and A.id= B.itemid第二条:
select A.id  from t_item A, t_yyy C 
where A.type = 2 and A.itemtype = 6 and A.id = C.itemid我个人觉得哈,这个我最迷茫的地方在这里: 第一条 sql里 是在 A.itemtype = 5 的情况下 去查找 A.id= B.itemid 这个的
 
 第二条 sql里 是在 A.itemtype = 6 的情况下 去查找 A.id = C.itemid 这个的而且吧,A表中的itemtype属性 还有 1,2,3,4 这四种属性值求大虾给些提示

解决方案 »

  1.   

    --1.
    SELECT A.id
      FROM t_item A, t_xxx B, t_yyy C
     WHERE A.id = B.itemid AND
           A.id = C.itemid AND
           A.type = 2 AND
           (A.itemtype = 5 OR A.itemtype = 6)
    --2.
    select A.id from t_item A , t_xxx B 
    where A.type = 2 and A.itemtype = 5 and A.id= B.itemid
    union all
    select A.id from t_item A, t_yyy C 
    where A.type = 2 and A.itemtype = 6 and A.id = C.itemid
      

  2.   

    呵呵,谢谢2楼啦~
     你的第二条sql可以实现哈~!  无限感激...
      

  3.   

    第一条:
    select A.id from t_item A , t_xxx B  
    where A.type = 2 and A.itemtype = 5 and A.id= B.itemid第二条:
    select A.id from t_item A, t_yyy C  
    where A.type = 2 and A.itemtype = 6 and A.id = C.itemid
    select A.id from t_item A join t_yyy C on A.id = C.itemid 
    join t_xxx B on A.id= B.itemid
    where A.type = 2 and A.itemtype in(5,6) 
      

  4.   

    select A.id from t_item A , t_xxx B  
    where A.type = 2 and A.itemtype = 5 and A.id= B.itemid
    union all
    select A.id from t_item A, t_yyy C  
    where A.type = 2 and A.itemtype = 6 and A.id = C.itemid