Example 1
Build a separator line and check a palindrome
REVERSE('racecar') = 'racecar' — it is the same forwards and backwards, so palindrome is 'yes'. REVERSE('hello') = 'olleh', which differs from the original, so palindrome is 'no'. REVERSE('level') = 'level' — another palindrome.
CREATE TABLE words (id INT, word VARCHAR(50));
INSERT INTO
words
VALUES
(1, 'racecar'),
(2, 'hello'),
(3, 'level');SELECT
id,
word,
REVERSE (word) AS reversed,
CASE
WHEN word = REVERSE (word) THEN 'yes'
ELSE 'no'
END AS palindrome
FROM
words
ORDER BY
id;| id | word | reversed | palindrome |
|---|---|---|---|
| 1 | racecar | racecar | yes |
| 2 | hello | olleh | no |
| 3 | level | level | yes |
REVERSE syntax is identical across MySQL, MariaDB, SQL Server, and PostgreSQL.