Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello sir,


I have table Called

Customer
SQL
Id     Name     Address
1      SUNIL    X
2      Mahesh   Y
3      Ajay     Z
4      Krunal   A



AddInfo
SQL
Id     Telephone   CustId(Foreign Key)
12      393939393   1
13      810241123   1
14      123232332   1
15      1232323     2
16      1232323     2
17      1232323     3


I want list of those customer whose Telephone No is present in AddInfo table.

O/p should be
SQL
Id     Name     Address
1      SUNIL    X
2      Mahesh   Y
3      Ajay     Z


Thanks,
Regards SUNIL
Posted
Updated 9-Jul-13 3:38am
v2

Hello Sunil,

You can use SQL INNER JOIN to retrieve the desired result.
SQL
SELECT DISTINCT c.id, c.name, c.address 
FROM customer AS c
    INNER JOIN addinfo AS a
        ON a.custid  = c.id

Regards,
 
Share this answer
 
Comments
sunil mali 10-Jul-13 1:12am    
Thanks It works.. :)
Hi sunil,
try this...:)


SQL
select Customer.Name,Customer.Address from Customer inner join AddInfo on Customer.Id=AddInfo.CustId
 
Share this answer
 
v3
Comments
sunil mali 10-Jul-13 1:11am    
not worked
Select 
      * 
from Customer
where 
      Id In
       (Select CustID from AddInfo)
-------------------------------------------------
--OR
-------------------------------------------------
Select 
     distinct CM.*
From 
     Addinfo AI
Inner Join 
     Customer CM
     On AI.CustID = CM.Id
 
Share this answer
 
v2
Comments
Nirav Prabtani 9-Jul-13 9:53am    
i can not understand second one.... :(
why you used "CM.*"
Amitava Bag (Kolkata) 9-Jul-13 9:57am    
Bcz the result actually need the column of Customer table.
sunil mali 10-Jul-13 1:12am    
Thanks It works.. :)

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