question

stianhjornevik avatar image
stianhjornevik asked

joining two table if containing same values.

table one ssn, name, branch table two ssn, name, branch the two tables may contain overlapping data. I want to take the cases where ssn = ssn and branch = branch and move it into a Third table. How can I do this?
join
2 comments
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

do you care if name=name?
0 Likes 0 ·
no. If the two others match name will also match, and I in the end I want to P(name)(Third table). But branch and ssn are the only two I check for
0 Likes 0 ·

1 Answer

· Write an Answer
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
INSERT INTO ThirdTable (ssn, branch, name) SELECT t1.ssn, t1.branch, t1.name FROM FirstTable t1 INNER JOIN SecondTable t2 ON t1.ssn=t2.ssn AND t1.branch = t2.branch; This would do the insert. But when you say "move", do you mean you also want to physically delete the rows from table1 and table2?
10 |1200 characters needed characters left characters exceeded

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.