[英]after making UNION ALL on two tables how could delete / update a specific row that has similer ID in other table?
i hope you understand my problem, on my db i have ord_detail
& custom_ord_detail
tables 我希望你理解我的问题,在我的数据库上,我有
ord_detail
和custom_ord_detail
表
ord_detail ord_detail
-------------------------------------------------
ordID | custID | productID |quantity | discount |
-------------------------------------------------
002 | 1 | 5 | 2 | 0 |
-------------------------------------------------
custom_ord_detail custom_ord_detail
--------------------------------------------------------
ordID | custID | custom_productID |quantity | discount |
--------------------------------------------------------
002 | 1 | 2 | 1 | 0 |
-------------------------------------------------
ordID
-> primary key auto_increment (in second table ordID
is primary key auto_increment , foreign key refere to table called custom_ord_reply
) ordID
>主键auto_increment(在第二个表中ordID
是主键auto_increment,外键custom_ord_reply
到名为custom_ord_reply
表)
custID
-> foreign key refer to customer table , productID
-> foreign key refer to products table , custom_productID
foreign key refer to custom_ord_reply table that the customer request the product in custom_ord_request table. custID
>外键引用客户表, productID
>外键引用产品表, custom_productID
外键引用custom_ord_request表中客户请求产品的custom_ord_reply表。
After we bring the specific product we store it into custom_ord_reply
, now we use ord_detail
& custom_ord_detail
when user added the product into cart and we use union all to show the all products in cart , if the customer want to update the quantity or delete specific product how can do this becouse they will be Duplicate values for the ordID
column , how could fix this problem ? 将特定产品带入后,我们将其存储到
custom_ord_reply
,现在,当用户将产品添加到购物车中时,我们使用ord_detail
和custom_ord_detail
;如果客户要更新数量或删除特定产品,则使用union all来显示购物车中的所有产品怎么做,因为它们将成为ordID
列的重复值,如何解决此问题? any idea union all with join 任何想法结合在一起
Viewing your query what I have in mind is add a new attribute/column in both queries as product_type
if ordID
in both table is unique ord_detail
, custom_ord_detail
查看您的查询是我心目中是两个查询中添加一个新属性/列
product_type
如果ordID
在这两个表是唯一ord_detail
, custom_ord_detail
'product' as product_type // 1st query
'custom' as product_type // 2nd query
If not then 2 new attributes/columns in your query, First product_type
as above second add some unique identifier for both queries like for first query include product id and for second query include request id (I assume request id from table custom_ord_request
is set to auto increment) 如果不是,那么您的查询中将有2个新属性/列,如上第二个
product_type
第一个product_type
,为两个查询添加一些唯一标识符,例如第一个查询包括产品ID,第二个查询包括请求ID(我假设来自表custom_ord_request
请求ID设置为auto增量)
SELECT p.id as uid, 'product' as product_type, od.ordID , p.prod_name , p.prod_descrip , p.price , od.quantity , od.discount
FROM ord_detail od
JOIN product p ON od.productID = p.productID
WHERE od.custlD = 1
UNION ALL
SELECT rq.id as uid, 'custom' as product_type, cod.ordID , rq.ord_title , rp.description , rp.price , cod.quantity cod.discount
FROM custom_ord_detail cod
JOIN custom_ord_reply rp ON cod.custom_prod_servID = rp.custom_prod_servID
JOIN custom_ord_request rq ON rp.ordID = rq.ordID
WHERE cod.custlD = 1
This way you could differentiate between your products and custom products for your cart. 这样,您可以区分您的产品和购物车的自定义产品。
Another way would be defining supertype/subtype relationship for your tables. 另一种方法是为表定义超类型/子类型关系。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.