日期:2014-05-18  浏览次数:20666 次

一个简单sql问题 下班结帖.
SQL code
select distinct a.*,b.LT_TEAMGROUP,c.li_name from TM_ORDER as a inner join LI_TM_CYCLETIME as b on a.TO_TEAM_ID=b.LT_ID LEFT join LI_LINEPRODUCT as c on a.TO_LINE_ID=c.LI_ID order by a.TO_ID desc

我想把上面的一个sql改成 以TM_ORDER 做为主表 查询的时候只要根据TM_ORDER 表条件查询就行(不要出现left join inner join之类 我想以tm_order做为主表 其它条件做子查询) 请问高手怎么改? thanks
原帖http://topic.csdn.net/u/20111227/15/1e0295ff-33a9-48c3-856b-0b31a0ed9aaf.html?693843235己结

------解决方案--------------------
是要这样吗:
SQL code
select distinct a.*,b.LT_TEAMGROUP,c.li_name from TM_ORDER as a 
, LI_TM_CYCLETIME as b  
, LI_LINEPRODUCT as c  

where a.TO_TEAM_ID=b.LT_ID  and  a.TO_LINE_ID *= c.LI_ID 

order by a.TO_ID desc

------解决方案--------------------
你不想用left join,inner join的理由是什么?
------解决方案--------------------
SQL code

select distinct a.*,b.LT_TEAMGROUP,c.li_name 
           from TM_ORDER  a,
                 LI_TM_CYCLETIME b, 
                 LI_LINEPRODUCT c 
           where a.TO_TEAM_ID=b.LT_IDon 
             and a.TO_LINE_ID=c.LI_ID 
           order by a.TO_ID desc