I'm trying to compare values ​​in two columns in two different tables
P粉311423594
P粉311423594 2024-04-04 20:05:03
0
1
393

I have two tables, tableA and tableB. Table A has 4 columns, while Table B has 3 columns. The last column of table A is blank and in this column I want to show the difference between the third column in tables A and B.

Table A name=valuation_average. Table B Name = Valuation_Cost. Their third column names are both cost_col (but the values ​​are different, I want to show this difference in the fourth column in tableA, called "difference", the column already exists and named it just has no value.)

Also remember that the rows may not be equal, I mean the first row in table A may be different from the first row in table B. The primary key is the first column of both tables, called "code"

P粉311423594
P粉311423594

reply all(1)
P粉764003519

You can try mysql-update-join.

In your case, maybe

UPDATE valuation_average a,valuation_cost c SET a.difference = a.cost_col - c.cost_col WHERE a.code = c.code

can solve your problem.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template