0

I have to tables. A table that we call "The Vault" which has a ton of demographic data and Table A which has some of the demographic data. I am new at SQL Server, and I was tasked with finding a list of 21 students in The Vault table (Table B). Problem, there is no primary key or anything distinctive besides, FirstName, LastName, BirthMonth, Birthday, Birthyear.

Goal: We could not match these people in the conventional way we have, and so we are attempting a Hail Mary to try to see which of these shared combinations will perhaps land us with a match.

What I have tried doing: I have placed both tables on tempt tables, table A and table B, and I am trying to do an Inner Join but then I realized that in order to make it work, I would have to do a crazy join statement where I say (see the code below)

But the problem as you can imagine is it brings a lot more than my current 21 records and is in the thousands so then I would have to make that join statement longer but I am not sure this is the right way to do this. I believe that is where the WHERE clause would come in no?

Question: How do I compare these two tables for possible matches using a WHERE clause where I can mix and match different columns without having to filter the data constrains in the ON clause of the JOIN. I don't want to JOIN on like 6 different columns. Is there another way to do this so I can perhaps learn. I understand this is easier when you have a primary key shared and that would be the JOIN criteria I would use, but when we are comparing two tables to find possible matches, I have never done that.

FROM #Table a
INNER JOIN #table b ON (a.LAST_NAME = B.LAST_NAME AND a.FIRST_NAME = b.FIRST_NAME.....)```
Hakka-4
  • 87
  • 8
  • Please provide sample data and desired results. This information is worth many paragraphs of text. – GMB Oct 12 '20 at 16:26
  • does this [SQL compare data from two tables](https://stackoverflow.com/questions/4602083/sql-compare-data-from-two-tables) answer your question? – Liz Oct 12 '20 at 16:34
  • So, the desired result is being able to match a person in table A to Table B based on those columns or a combination of them. – Hakka-4 Oct 12 '20 at 16:43
  • @Hakka-4 by sample data and desired results, we are asking you to actually add a small sample of data and the resulting dataset i.e. a [mre]. Trying to explain in words is just not as clear. Ideally use DDL/DML statements to create a temp table and insert some data. – Dale K Oct 12 '20 at 19:16

0 Answers0