Compare fields between two tables in PHP x Mysql

Asked

Viewed 616 times

1

Good morning, I need some help with some php tables. 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 Tabela1 with columns A,B,C,D and table2 with columns A,B,C, I need to compare columns A,B,C and if they are equal return me the value of column D, where if D is equal to x the total value of records should go to 1/3 of a graph and if D is different from x 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 I already have. Can someone help me? Thank you.

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

...

Tabela 2
-------------
A | B | C

1 answer

0

You can do as follows with the comparison expression that acts as JOIN Inner 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)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.