I joined two tables using following query. It is giving me duplicates because Table02 has duplicates. I need to prevent dupes.
Note:
- I can’t change the order/sequence of the columns in my select statment.
-
I can’t use distinct on t1.NumberID.
SELECT t1.NumberID, t1.Copies, t1.NameStreet
FROM Table01 t1
JOIN Table02 t2
on t2.Name = LEFT(t1.NameStreet, Len(t2.Name)) order by t1.NumberID, t1.Namestreet
Table01
ID NumberID Copies NameStreet
1 11111111 2 Julian Assange 100 Majestic street, Toronto
2 22222222 1 Brad Pit 200 Loaden Blvd, Toronto
3 11111111 0 Allen Sunderland 9, Unit 2, Janet Street, BC
Table02
ID Name
1 Julian Assange
2 Allen Sunderland
3 Julian Assange
Results:-
1 11111111 2 Julian Assange 100 Majestic street, Toronto
3 11111111 0 Allen Sunderland 9, Unit 2, Janet Street, BC
1 11111111 2 Julian Assange 100 Majestic street, Toronto
Expected Results:-
1 11111111 2 Julian Assange 100 Majestic street, Toronto
3 11111111 0 Allen Sunderland 9, Unit 2, Janet Street, BC
Add this to the end of the query: