I need to select a different value from the query depending on whether a certain part of the WHERE clause matches the result or not. While I have the logic of what needs to be achieved, I have absolutely no idea how to label this in a MySQL-friendly way!
Consider the following pseudo code:
SELECT table_name.*, `match_type` FROM table_name WHERE ( IF THIS MATCHES: 'input' LIKE CONCAT('%', `value`, '%'); THEN `match_type` equals 1 ELSEIF THIS MATCHES: `value` LIKE CONCAT('%', 'input', '%') `match_type` equals 0 )
If this first match finds any results, then I need to return a match_type column with a value of 1.
Otherwise, go to the second test. If this second match returns any results, then I need a match_type column so that it has a value of 0 instead.
If there are no matches, nothing needs to be returned. Thus, the only possible parameters for match_type should be 1 or 0.
How can i do this?
Thanks for your help!
source share