1

こんにちは、誰かがアドバイスできることを願っています

実行されたSQLクエリがありますが、作成されたユーザー(エントリ)の数だけ同じ結果が繰り返されます

例えば:

post_id
20
20
19
19
18
18

これは引数を取らないクエリです。なぜこれが起こっているのか誰か説明してもらえますか?

ありがとう

SELECT DISTINCT post_look.post_id, post_look.look_id, post_look.date_posted,     looks.title, looks.item_id, user.user_id, user.first_name, user.last_name,    user_account.profile_image, user_account.account_status, add_profile_images.image_name
FROM post_look
JOIN looks ON looks.look_id = post_look.look_id
JOIN add_look_item ON add_look_item.look_id = looks.look_id
JOIN item ON item.item_id = add_look_item.item_id
JOIN add_images ON add_images.item_id = item.item_id
JOIN user_item ON user_item.item_id = item.item_id
JOIN user_account ON user_account.account_id = user_item.account_id
JOIN user ON user.user_id = user_account.user_id
JOIN users_profile_images ON users_profile_images.account_id = user_account.account_id
JOIN add_profile_images ON add_profile_images.image_id = users_profile_images.image_id
ORDER BY post_look.post_id DESC 
LIMIT 0 , 30
4

2 に答える 2

4
SELECT DISTINCT c1, c2, c3

{c1, c2, c3}区別されることを意味します。

クエリに追加することを検討する必要がありGROUP BY post_look.post_idます。

ここで違いを見てください:

于 2012-04-14T07:34:19.397 に答える
1

試してみませんか?

SELECT post_look.post_id, post_look.look_id, post_look.date_posted,     looks.title, looks.item_id, user.user_id, user.first_name, user.last_name,    user_account.profile_image, user_account.account_status, add_profile_images.image_name
FROM post_look
JOIN looks ON looks.look_id = post_look.look_id
JOIN add_look_item ON add_look_item.look_id = looks.look_id
JOIN item ON item.item_id = add_look_item.item_id
JOIN add_images ON add_images.item_id = item.item_id
JOIN user_item ON user_item.item_id = item.item_id
JOIN user_account ON user_account.account_id = user_item.account_id
JOIN user ON user.user_id = user_account.user_id
JOIN users_profile_images ON users_profile_images.account_id = user_account.account_id
JOIN add_profile_images ON add_profile_images.image_id = users_profile_images.image_id
GROUP BY post_look.post_id
ORDER BY post_look.post_id DESC 
LIMIT 0 , 30
于 2012-04-14T07:39:20.970 に答える