yasen
yasen

Reputation: 39

query mysql in php to get the difference between two tables

I have two tables with the same structure to get users finger print data and i want to get from the first table data that is not exist in the second table and insert it into the second table the structure of two tables:

Upvotes: 0

Views: 80

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44874

You can use insert into select from using some additional join as

insert into table2 
select 
t1.* from table1 t1
left join table2 t2 on t1.user_id = t2.user_id and t1.check_time = t2.check_time
where t2.user_id is null and t2.check_time is null

Upvotes: 1

Related Questions