cli130
cli130

Reputation: 349

Querying multiple values from multiple columns in MySQL

I'm trying to query by a list of value pair.

For example:

src   dst   byte
 a     b     16
 c     d     20
 e     f     50
 a     f      0

I want to query by src and dst in one Query to get (a, b, 16) and (e, f, 50).

SELECT *
FROM table
WHERE src IN ( a, e )
AND dst IN (b, f )

But this statement also gives me (a, f, 0).

Is it possible to get (a, b, 16) and (e, f, 50) in one query?

Upvotes: 0

Views: 117

Answers (2)

Sadikhasan
Sadikhasan

Reputation: 18600

Do simple things like

SELECT *
FROM your_table
WHERE (src = 'a' AND dst = 'b')
   OR (src = 'e' AND dst = 'f');

Upvotes: 1

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

Try this:

SELECT *
FROM table
WHERE src = 'a' AND dst = 'b'
   OR src = 'e' AND dst = 'f'

Upvotes: 2

Related Questions