日期:2014-05-17  浏览次数:20347 次

full join 怎么不行啊???
select * from  UT_PROGRAM where userid=4   有142条数据
select * from  UT_PROGRAM where userid=50437有165条数据

以上两个结果中 ProgramID 相同的只有1条

其中 UT_PROGRAM 表有4个字段 [UserID],[ProgramID],[Weight] ,[Type]

select * from  UT_PROGRAM u1
full  join (select * from  UT_PROGRAM where userid=4 ) u2 on u2.ProgramID=u1.ProgramID

 where u1.userid =50437


这样操作却只出165条记录 .

为什么呢 ???


------最佳解决方案--------------------
where u1.userid =50437 不等于 on u1.userid =50437
------其他解决方案--------------------
试试,楼主写的有问题
select *
from (select * from  UT_PROGRAM u1 where userid =50437) as u1
full  join (select * from  UT_PROGRAM where userid=4 ) u2 on u2.ProgramID=u1.ProgramID  

------其他解决方案--------------------
说错了 理解错你的意思了
select * from  UT_PROGRAM u1
full  join (select * from  UT_PROGRAM where userid=4 ) u2 on u2.ProgramID=u1.ProgramID
这句话结果是 UT_PROGRAM 所有数据
  where u1.userid =50437 筛选出来是select * from  UT_PROGRAM where userid=50437的数据
------其他解决方案--------------------
你想要的写法应该是

SELECT  * FROM    ( SELECT    *   FROM      UT_PROGRAM   WHERE     userid = 50437 ) u1 full JOIN ( SELECT   *  FROM     UT_PROGRAM    WHERE    userid = 4 ) u2 ON u2.ProgramID = u1.ProgramID
结果应该是142+165-1条
------其他解决方案--------------------
用full的话应该是142+165-1条记录啊,求大神指教
------其他解决方案--------------------
full是全连 应该用内连把full去掉
------其他解决方案--------------------
用inner join
SELECT  *
FROM    ( SELECT    *
          FROM      UT_PROGRAM
          WHERE     userid = 50437
        ) u1
        INNER   JOIN ( SELECT   *
                       FROM     UT_PROGRAM
                       WHERE    userid = 4
                     ) u2 ON u2.ProgramID = u1.ProgramID

------其他解决方案--------------------