Matt Moseley
Matt Moseley

Reputation: 69

Select from table using multiple conditions

I have the following table:

| id | market | source | event |
+----+--------+--------+-------+
| 1  |   1    |   1    |   1   |
| 2  |   1    |   2    |   1   |
| 3  |   2    |   1    |   1   |
| 4  |   3    |   1    |   2   |
| 5  |   1    |   3    |   1   |

I want to be able to select rows where (market = 1 AND event = 1) and also where (market = 3 AND event = 2). Can someone point me in the right direction?

Upvotes: 1

Views: 31

Answers (4)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57640

where (market = 1 AND event = 1) ALSO where (market = 3 AND event = 2) above can be converted to

WHERE (market = 1 AND event = 1)  OR (market = 3 AND event = 2)

Upvotes: 1

Jens
Jens

Reputation: 69440

This should be the select you need:

select * from `table` where  (market = 1 AND event = 1) or (market = 3 AND event = 2)

Upvotes: 1

Saharsh Shah
Saharsh Shah

Reputation: 29051

Try this:

SELECT source 
FROM tableA 
WHERE (market = 1 AND event = 1)  OR 
      (market = 3 AND event = 2) 
GROUP BY source 
HAVING COUNT(1) = 2;

Upvotes: 0

dhalik
dhalik

Reputation: 465

Replace t_table with your table name here:

Select * from t_table where (market = 1 and event = 1) or (market = 3 and event = 2)

Upvotes: 0

Related Questions