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 回答