>>create table #Customers (CustomerID int, CustomerName varchar(50)) >>create table #Products (ProductID int, ProductName varchar(50), Price Money) >>create table #Sales (ProductID int, CustomerID int, Quantity int) >> >>insert into #Customers (CustomerID, CustomerName) values (1, 'Robert'), (2, 'James'), (3, 'Anderson') >>insert into #Products (ProductID, ProductName, Price) values (1, 'Apple', 1), (2, 'Orange', 5.3), (3, 'Grapes', 2) >>insert into #Sales (ProductID, CustomerID, Quantity) values (1, 1, 1), (1, 2, 3), (2, 1, 2), (3, 1, 5), (2, 2, 2), (1, 1, 1) >> >>select distinct >> Cust.CustomerId, >> Cust.CustomerName >> from #Customers Cust >> inner join #Sales Sp1 On Cust.CustomerId = Sp1.CustomerId and Sp1.ProductID = (select ProductID from #Products where ProductName = 'Orange') >> inner join #Sales Sp2 On Cust.CustomerId = Sp2.CustomerId and Sp2.ProductID = (select ProductID from #Products where ProductName = 'Apple') >> >>drop table #Customers >>drop table #Products >>drop table #Sales >>>