So, I have a work problem I’ve been looking at for a bit, I’ve created a very simple example, and this could be easy and I’m just overthinking it, or the complete opposite. I just need another pair of eyes or brain to help me out.
Here’s a SQLFiddle – https://sqlfiddle.com/sql-server/online-compiler?id=b18e6800-424f-49b1-a324-df1c89fc482f
CREATE TABLE Party (
Partyid varchar(10),
Name VARCHAR(100),
FruitCode Varchar(50),
Description VARCHAR(255));
INSERT INTO Party(PartyID, Name, FruitCode, Description) VALUES ('123','John', 'A', 'Apple');
INSERT INTO Party(PartyID, Name, FruitCode, Description) VALUES ('456','Jane', 'O', 'Orange');
INSERT INTO Party(PartyID, Name, FruitCode, Description) VALUES ('789', 'Jack', 'A', 'Apple');
INSERT INTO Party(PartyID, Name, FruitCode, Description) VALUES ('789', 'Jack', 'O', 'Orange');
INSERT INTO Party(PartyID, Name, FruitCode, Description) VALUES ('012', 'Jill', 'O', 'Apple');
INSERT INTO Party(PartyID, Name, FruitCode, Description) VALUES ('123', 'John', 'O', 'Orange');
SELECT * FROM Party
What I’m trying to achieve is to split each of these people into their own groups depending on which type of fruit they have. There’s 3 possible groups, Apple, Orange, and both Apple and Orange.
John and Jack should belong to the group that have both fruits, while Jane and Jill belong to groups who possess Oranges and Apples respectively.
Any help would be great, thanks in advance.