Compare fields between two tables in PHP x MySQL

1

Good morning, I'm in need of some help with some tables in php. I have two tables from which I need to compare data, the tables are in a database in MySQL. The scenario is as follows: I have table1 with columns A, B, C, D and table2 with columns A, B, C, I need to compare the columns A, B, C and if they are the same I return the value of column D, where D is equal to x the total value of records should go to 1/3 of a graph and if D is different from xo the total value of records should go to another 1/3 of the graph, the other 1/3 of the graph will be populated with another information that I already have. Can anybody help me? Thank you.

Tabela 1
-------------
A | B | C | D

...

Tabela 2
-------------
A | B | C
    
asked by anonymous 27.01.2018 / 13:18

1 answer

0

You can do this with the comparison expression that acts as inner JOIN in SQL:

SELECT tabela1.a, tabela1.b, tabela1.c, tabela1.d FROM tabela1 tabela1, 
tabela2 tabela2
WHERE tabela1.a = tabela2.a
AND tabela1.b = tabela2.b
AND tabela1.c = tabela2.c2
AND (ValorX is null or tabela1.d = ValorX)
    
27.01.2018 / 13:46