stackoverflow.com/questions/9708925/sql-query-to-select-from-same-column-but-multiple-values

0

Please login or register to vote for this query.

(click on this box to dismiss)

Christianity

Q&A for committed Christians, experts in Christianity and those interested in learning more

DECLARE @table AS TABLE (id INT, customer VARCHAR(50), product varchar(50));

INSERT INTO @table VALUES (1, 'Tizag', 'Pen'), (4, 'Gerald Garner', '19" LCD Screen'), (5, 'Tizag', '19" LCD Screen');

SELECT DISTINCT customer FROM @table t1
WHERE EXISTS (SELECT * FROM @table WHERE product = 'Pen' AND customer = t1.customer)
    AND EXISTS (SELECT * FROM @table WHERE product = '19" LCD Screen' AND customer = t1.customer)

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results