I have 2 tables in SQL, namely Pets and Customers
Pets table:
Pet ID | PetType |
---|---|
01 | Dog |
02 | Cat |
03 | Mouse |
04 | Fish |
Customer table:
CustID | CustName | PetType | IsPet |
---|---|---|---|
01 | Cust1 | Dog | Y |
02 | Cust2 | Cat | Y |
03 | Cust3 | Dog | Y |
04 | Cust4 | Fish | Y |
05 | Cust5 | Mouse | Y |
06 | Cust6 | Dog | Y |
I need to select the records in such a way that the list of Customer are joined with pivoted columns for the pets. For example, the result should be:
CustID | CustName | Dog | Cat | Mouse | Fish |
---|---|---|---|---|---|
01 | Cust1 | Yes | |||
02 | Cust2 | Yes | |||
03 | Cust3 | Yes | |||
04 | Cust4 | Yes | |||
05 | Cust5 | Yes | |||
06 | Cust6 | Yes |
Any advice or help for the SQL query would be greatly appreciated.