当前位置: 代码迷 >> PHP >> sql,去重查询distinct解决办法
  详细解决方案

sql,去重查询distinct解决办法

热度:96   发布时间:2016-04-28 18:14:47.0
sql,去重查询distinct
 

select DISTINCT `object_id`, t3.width as width, t3.height as height,t3.ismark as ismark, t2.rtime as add_time,t1.add_author as add_author,t1.image_url as image_url,t1.id as id,t1.browse_real_cnt as browse_real_cnt 
from comments as t2 
left join ornamentations as t1 on t1.id = t2.object_id 
left join ornamentation_images as t3 on t3.ornamentation_id = t1.id 
where ( t2.uid = 1013 ) AND ( t1.enable = '0' ) 
ORDER BY t2.id desc LIMIT 0,5 


select后面的条件,带t3正常,能去重复的,加了t2,t1就没法去重复的了
------解决思路----------------------
DISTINCT 作用于整行
你的3个表中只要存在一对多的情况就难说了
  相关解决方案