ホームページ  >  記事  >  バックエンド開発  >  SQL、個別の重複排除クエリ

SQL、個別の重複排除クエリ

WBOY
WBOYオリジナル
2016-06-23 13:44:483406ブラウズ

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 つのテーブルに 1 対多の状況があると言うのは難しいでしょう

DISTINCT は行全体に作用します
3 つのテーブルに 1 対多の状況がある限り、次のようになります言うのは難しいです


では、どう書けばよいでしょうか? チェックした、1つのテーブルにdistinctを使用し、複数のテーブルがある場合は使用しないと言いました

別のselectを使用してください

select DISTINCT * from   (`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) T LIMIT 0,5

別の select を使用してください

select DISTINCT * from   (`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) T LIMIT 0,5


エラーを報告し、t2 としてコメントから報告してください
from が間違っています
ああ、select

..... from
( select `object_id`, t3.width as ....

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。