mysql check if record exists code example
Example 1: check if record exists mysql
-- Returns 1 if exists, 0 else
SELECT EXISTS(SELECT 1 FROM my_table WHERE text LIKE '%something%');
SELECT
CASE
WHEN EXISTS(SELECT 1 FROM my_table WHERE text LIKE '%something%') = 1 THEN
'It exists'
ELSE 'Does not exist'
END;
Example 2: mysql check if value exists
mysql> SELECT EXISTS(SELECT * from ExistsRowDemo WHERE ExistId=105);