Thursday 30 August 2018

PHP - Compare two tables and store the result in the third table

I have two tables in my database.

I want to compare the each row of email of table-1 with the each row of email2 of table-2 if their content matches then I want to store the mac of table-1 to Mac of Result table .

this is table-1

Email    Mac
value1 21321
value2 45666

this is table-2

Name   email2
name1  xyyxas
name2  xxxxxx

this is Result Table

ID      Mac
1     21321
2     45666

I am completely out of logic here I tried join queries but they doesn't seem to be fit in my case.
I am well aware the similar questions is being asked before but none of them is like my question or has complete a answer that's why I asked

you can use a insert select with inner join
insert into result_table (mac)
select table1.mac from table1
inner join table2 on table1.email = table2.email

0 comments:

Post a Comment