How can I update sales
in products
table depending on sales
of productsUPDATE
where products.id
= productsUPDATE.id
and while retaining the previous data numbers of products
?
These are my two tables:
# products # productsUPDATE
id Sales id Sales
---|-----| ---|-----|
1 | 10 | 1 | 40 |
2 | 11 | 2 | 50 |
3 | 12 | 3 | 80 |
I try this query but I lose data sales in products
table:
UPDATE products
INNER JOIN productsUPDATE ON products.id = productsUPDATE.id
SET products.sales = productsUPDATE.sales
WHERE productsUPDATE.id = products.id
query ouput:
# products # productsUPDATE
id Sales id Sales
---|-----| ---|-----|
1 | 40 | 1 | 40 |
2 | 50 | 2 | 50 |
3 | 80 | 3 | 80 |
desired output:
# products # productsUPDATE
id Sales id Sales
---|--------| ---|-----|
1 | 40,10 | 1 | 40 |
2 | 50,11 | 2 | 50 |
3 | 80,12 | 3 | 80 |
2
Answers
You can use the following solution using
CONCAT_WS
:Instead of storing the data on the
products
table, you can also use aVIEW
:Seems you want comma separated values
but you should avoid the use comma separated values you should take a look at normalization ..