gpt4 book ai didi

MySql|选择所有带有内连接的内容,没有重复的值

转载 作者:行者123 更新时间:2023-11-29 15:11:19 24 4
gpt4 key购买 nike

这是我的查询:

SELECT * FROM Products as pr
INNER JOIN Customers as ct
ON ct.supplierUUID = pr.supplierUUID
LEFT JOIN FavoriteProducts as fp
ON ct.customerUUID = fp.favoriteCustomerUUID
WHERE ct.customerUUID = '101049356085569448728'

我得到以下结果:

+------------+-------------+--------+------------------+-------------+ ... and so
|productsID |productName | price |favoriteProductID |customerID |
+------------+-------------+--------+------------------+-------------+
| 1 | apple | 3 | 1 | 123 |
+------------+-------------+--------+------------------+-------------+
| 1 | apple | 3 | 1 | 123 |
+------------+-------------+--------+------------------+-------------+
| 2 | computer | 10 | 2 | 123 |
+------------+-------------+--------+------------------+-------------+
| 2 | computer | 10 | 2 | 123 |
+------------+-------------+--------+------------------+-------------+


如何选择所有内容而不重复?

我希望结果是这样的:

+------------+-------------+--------+------------------+-------------+ ... and so
|productsID |productName | price |favoriteProductID |customerID |
+------------+-------------+--------+------------------+-------------+
| 1 | apple | 3 | 1 | 123 |
+------------+-------------+--------+------------------+-------------+
| 2 | computer | 10 | 2 | 123 |
+------------+-------------+--------+------------------+-------------+

我尝试添加 GROUP BY 但出现错误

SELECT * FROM Products as pr
Inner JOIN Customers as ct
ON ct.supplierUUID = pr.supplierUUID
LEFT JOIN FavoriteProducts as fp
ON ct.customerUUID = fp.favoriteCustomerUUID
where ct.customerUUID = '101049356085569448728'
**GROUP BY pr.productID**;

谢谢!!

最佳答案

您可以使用 DISTINCT

SELECT DISTINCT productsID, productName, price, favoriteProductID, customerID   
FROM Products as pr
INNER JOIN Customers as ct ON ct.supplierUUID = pr.supplierUUID
LEFT JOIN FavoriteProducts as fp ON ct.customerUUID = fp.favoriteCustomerUUID
WHERE ct.customerUUID = '101049356085569448728'

关于MySql|选择所有带有内连接的内容,没有重复的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60035891/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com