mysql - SQL 返回重复值

标签 mysql sql

我的 SQL 查询有问题,因为它返回多行,我希望仅从

获取值

ps_tax t

有人可以帮助我吗?

SELECT bgc.id_product,bgc.id_order, tx.id_tax_rules_group,t.id_tax,pl.name,t.rate as rate, brl.price as gift_price
FROM ps_bestkit_gift_cart bgc
LEFT JOIN ps_bestkit_gift_rule brl ON brl.id_bestkit_gift_rule = bgc.id_bestkit_gift_rule
LEFT JOIN ps_product_lang pl ON bgc.id_product = pl.id_product
LEFT JOIN ps_product p ON pl.id_product = p.id_product
LEFT JOIN ps_tax_rule tx ON p.id_tax_rules_group = tx.id_tax_rules_group
LEFT JOIN ps_tax t ON tx.id_tax = t.id_tax
WHERE id_order =8452
AND pl.id_lang=3
AND tx.id_country=6

There is a screenshot of my result

DDL

创建表 ps_bestkit_gift_rule ( id_bestkit_gift_rule int(11) 无符号非空自动递增, is_product_depends tinyint(1) 无符号 DEFAULT NULL, is_supplier_depends tinyint(1) 无符号 DEFAULT NULL, is_manufacturer_depends tinyint(1) 无符号 DEFAULT NULL, is_category_depends tinyint(1) 无符号 DEFAULT NULL, is_attribute_depends tinyint(1) 无符号 DEFAULT NULL, is_feature_depends tinyint(1) 无符号 DEFAULT NULL, is_allow_other_gift tinyint(1) 无符号 DEFAULT NULL, cart_amount 小数(17,2) 无符号 NOT NULL, max_cart_amount 十进制(17,2) 无符号 NOT NULL, 价格小数(17,2)无符号NOT NULL, min_qty_inside_category int(10) 无符号 NOT NULL 默认 0, min_price_inside_category 小数(17,2) 无符号 NOT NULL, from_date 日期不为空, to_date 日期不为空, criteria_order_type varchar(32) NOT NULL, criteria_max_per_customer int(11) 无符号 NOT NULL, criteria_nb_products int(11) 无符号 NOT NULL, Gift_preselector_product_page tinyint(1) 无符号 DEFAULT NULL, available_gifts int(10) 无符号 NOT NULL 默认 1, criteria_优惠券文本, criteria_customer_group 文本, 消息 tinyint(1) 无符号 DEFAULT NULL, 事件的tinyint(1)无符号DEFAULT NULL, 位置 int(10) 无符号 NOT NULL 默认 0, 主键(id_bestkit_gift_rule) ) ENGINE=MyISAM AUTO_INCRMENT=6 DEFAULT CHARSET=utf8

最佳答案

我认为GROUP BY会完成这项工作。

SELECT bgc.id_product,bgc.id_order,
tx.id_tax_rules_group,t.id_tax,pl.name,t.rate as rate, brl.price as gift_price 
FROM ps_bestkit_gift_cart bgc
LEFT JOIN ps_bestkit_gift_rule brl ON brl.id_bestkit_gift_rule = bgc.id_bestkit_gift_rule 
LEFT JOIN ps_product_lang pl ON bgc.id_product = pl.id_product 
LEFT JOIN ps_product p ON pl.id_product = p.id_product 
LEFT JOIN ps_tax_rule tx ON p.id_tax_rules_group = tx.id_tax_rules_group 
LEFT JOIN ps_tax t ON tx.id_tax = t.id_tax 
WHERE id_order =8452 
AND pl.id_lang=3 
AND tx.id_country=6
GROUP BY t.id_tax

关于mysql - SQL 返回重复值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46321591/

相关文章:

mysql - SQL - 如果 id 的所有 bool 值都为真则更新

sql - 在所有其他值之后对空值进行排序,特殊情况除外

sql - 如何使用 JOIN 而不是 UNION 来计算 "A OR B"的邻居?

php - 将 Google 日历与 SQL 数据库同步(以及其他方式)?

mysql - 简单的更新查询需要很长时间才能在 MySQL 中执行

mysql - 查看已知数据库?

MySQL TIMESTAMP 到 QDateTime 以毫秒为单位

sql - 对 mySQL 中两个表的总和进行排序

sql - 如何在保持外键关系/参照完整性的同时在多个数据库的表之间移动数据?

sql - 表达解释