aakashgupta.0205 aakashgupta.0205 - 2 years ago 79
SQL Question

SQL comparing all values in a many-one table

I have a table as follows

column1 column2
a 1
a 2
b 2

I need to write an sql query that will go through the table and return me all column 2 values that have both a and b in column 1.

Answer Source

Try this:

SELECT column2
FROM mytable
WHERE column1 IN ('a', 'b')
GROUP BY column2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download