MySQL Forums
Forum List  »  PHP

Re: Compare Two Tables and Insert Missing Foreign Keys
Posted by: Peter Brawley
Date: April 17, 2021 09:00PM

t2.related_id refers to t1.id?

-- t1.id values missing from t2:
select t1.id
from t1
left join t2 on t1.id=t2.related_id
where t2.related_id is null;

Why do you need every t1.id represented in t2? Does the requirement stipulate values for other t2 row values? Perhaps you could explain what problem you're solving?

Options: ReplyQuote


Subject
Written By
Posted
Re: Compare Two Tables and Insert Missing Foreign Keys
April 17, 2021 09:00PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.