SQL find which OR was mapped

In a statement like:, SELECT * FROM tbl1 WHERE row1=val1 OR row2=val2is it possible to find out which string was matched? If so, how can this be done? And how would you capture this in PHP?

+4
source share
1 answer

Use operator Case/IF

SELECT *,
       case when row1='val1' then 'row1' else 'row2' end as matched col
FROM tbl1
WHERE row1='val1' OR row2='val2'
Operator

Casecan be replaced by the operator IFas follows

IF(row1='val1','row1','row2')
+4
source

Source: https://habr.com/ru/post/1627577/


All Articles