Home > Back-end >  Select customers with multiple addresses
Select customers with multiple addresses

Time:03-03

enter image description here

I have a customer table and want to select customers with multiple addresses.

I create the following query, but the customer(105) with the same address and different account is coming to my result

select *
from [Cutomer]    
where Customer_ID in (
   select [Customer_ID]       
   from [CuatomerA]
   group by [Customer_ID]
   having count(*) > 1
)

CodePudding user response:

select *
from [Cutomer]    
where Customer_ID in (
   select [Customer_ID]       
   from [CuatomerA]
   group by [Customer_ID]
   having count(distinct [Address]) > 1
)
  • Related