I have a MySQL table where two of the fields are supposed to be unique. As new data is offered up I need to check if it already exists, and so would like to do something like (PDO parameters included):
SELECT COUNT(foo),COUNT(bar)
FROM `mytable`
WHERE foo=:foo
OR bar=:bar;
The problem here is that if both values will come back with identical counts, so in the event of that count being 1 I don’t know which column contains the matching value. Obviously I could split this into 2 queries, but is there a neater way to check both at once?
Maybe something like this: