I have a Select Statement with a lot of data, over 23K, it's joined with over 5 tables one of which is causing the duplicates when I looked at the table I see that the join I am doing have 2 rows matching,
I tried doing a Group by but that didn't work, I also tried to Select DISTINCT but that also didn't work, how would I go about this?
SELECT DISTINCT FirstName, LastName, F.Interview FROM tbData D
LEFT JOIN tbInterview F on D.UserID = F.UserID
where CreatedDate is between '' and ''
That returned Duplicates because the tbInterview has more than one Interviews linking the USerID, Then I tried This
SELECT DISTINCT FirstName, LastName, F.Interview FROM tbData D
LEFT JOIN (Select UserID from tbInterview GROUP BY UserID) as InterviewID ON D.UserID = InterviewID.UserID
LEFT JOIN tbInterview F on InterviewID.UserID = F.UserID
where CreatedDate is between '' and ''
This didn't work either.
Here is an example of data in the table tbInterview
╔═════════════╤════════╤═════════════╤═════════════════════════════╗
║ InterViewID │ UserID │ DateCreated │ Interview ║
╠═════════════╪════════╪═════════════╪═════════════════════════════╣
║ 1 │ 120 │ 2015/05/10 │ Inter View Done ║
╟─────────────┼────────┼─────────────┼─────────────────────────────╢
║ 2 │ 120 │ 2015/05/15 │ 2nd Interview was requested ║
╚═════════════╧════════╧═════════════╧═════════════════════════════╝
Now when I do a Select with the Join to the tbInterview it shows the output as follows:
╔═══════════╤══════════╤═════════════════════════════╗
║ FirstName │ LastName │ Interview ║
╠═══════════╪══════════╪═════════════════════════════╣
║ James │ Smith │ Inter View Done ║
╟───────────┼──────────┼─────────────────────────────╢
║ James │ Smith │ 2nd Interview was requested ║
╚═══════════╧══════════╧═════════════════════════════╝