Click here to Skip to main content
15,850,359 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have following tables.Here I have mentioned few cols of tables.

Table 1:
Id RefId PhoneNumber 
1  11    919191
2  11    888888
3  11    919191

Table 2:
Id RefId City    UniqueId
1  11    Mumbai  111
2  11    Pune    222
3  11    Nashik  333

I wants few cols from Table1 and Table2.Common in both table is RefId.Table 2 has UniqueId which is primary key of Table2. If I do inner join base on refId,will get 9 record.But I want 3,how to fetch that?


What I have tried:

select T1.PhoneNumber,T2.City,T2.UniqueId,T2.RefId
From Table1 T1
Inner Join Table2 T2
on T1.RefId = T2.RefId
Posted
Updated 20-Sep-17 2:02am

1 solution

if there are any duplicated values that you don't want just use the distinct.


example if there are duplicates phone numbers make:

select distinct (T1.PhoneNumber) ,T2.City,T2.UniqueId,T2.RefId
From Table1 T1
Inner Join Table2 T2
on T1.RefId = T2.RefId
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900