Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting a row where, 1=a, 2=b OR 1=b, 2=a

Tags:

sql

mysql

I have a form that is giving me information like INPUT1, INPUT2. I need to select from COL1 and COL2 where COL1 = INPUT1, COL2 = INPUT2 or the other way around, COL1 = INPUT2, COL2 = INPUT1.

like image 920
Justin Avatar asked Dec 28 '22 02:12

Justin


2 Answers

SELECT * FROM table WHERE 
                      (COL1 = INPUT1 AND COL2 = INPUT2) 
                   OR (COL1 = INPUT2 AND COL2 = INPUT1);
like image 143
Femaref Avatar answered Jan 18 '23 23:01

Femaref


SELECT * FROM table
WHERE ( COL1=INPUT1 AND COL2=INPUT2 ) 
   OR ( COL1=INPUT2 AND COL2=INPUT1 ) 
like image 34
bensiu Avatar answered Jan 18 '23 23:01

bensiu