I’m trying to find duplicates in a table. The field that needs to be checked against duplicate is a serialized array from PHP. This is my query:
SELECT Blob, BID, ID
FROM `Statuses`
WHERE ID <> :id AND (Blob LIKE :blob1 OR Blob LIKE :blob2)
now what i want from this query is that select all of those statuses that are not the status that im trying to match with and their serialized array contains :blob1 OR serialized array contains :blob2.
This works, it returns the duplicates just fine but i need to know which one it matched, whether it matched blob1 or it matched blob2. Is it possible to do this directly from Query without using PHP?
In other words, is it possible to find out which field matched to find the duplicate.
This should work:
Although that means the blob is compared twice (once for the CASE and once for the WHERE clause). I don’t know how much overhead that is.
Here is a SQLFiddle example (although not using blobs or variables): http://sqlfiddle.com/#!2/3fc41/6