I have four tables and am trying to get a list of all products ever purchased. The tables are
Guest - GuestID
Ticket - GuestID, TicketID
TicketItem - ProductID,TicketID,TicketItemID
Product - productID
What is a query that would give me a list of all products purchased by one person?
I got a count of items this way but can't ge tthe list of products.
SELECT G.GuestID
, COUNT(TL.ProductID) Purchases
, SUM(TL.Quantity) ProductsPurchased
FROM dbo.Guest G
INNER JOIN dbo.Ticket T ON G.guestid = T.guestid
INNER JOIN dbo.TicketItem TL ON T.ticketID = TL.ticketID
WHERE G.GuestID = '1234'
GROUP BY G.guestID
HAVING COUNT(TL.ProductID) > 0
ORDER BY ProductsPurchased
Guest - GuestID
Ticket - GuestID, TicketID
TicketItem - ProductID,TicketID,TicketItemID
Product - productID
What is a query that would give me a list of all products purchased by one person?
I got a count of items this way but can't ge tthe list of products.
SELECT G.GuestID
, COUNT(TL.ProductID) Purchases
, SUM(TL.Quantity) ProductsPurchased
FROM dbo.Guest G
INNER JOIN dbo.Ticket T ON G.guestid = T.guestid
INNER JOIN dbo.TicketItem TL ON T.ticketID = TL.ticketID
WHERE G.GuestID = '1234'
GROUP BY G.guestID
HAVING COUNT(TL.ProductID) > 0
ORDER BY ProductsPurchased