My main goal is to search in a column for a specific value (say word). If it doesn't exist, want to find the first that matches word% or wor% or wo% or w%.
In "English", the query would read like: "look for 'word' and return it if it exists. If not, look for the first word that has the maximum same prefix as 'word'".
I can write
SELECT word FROM words WHERE word = 'word' or word LIKE 'word%' or ... LIMIT 1;
I was trying to order by alphabetically, but it won't work (wo comes before wor). Also, can't order in reverse order, or 'wordy' will come before 'word'.
My current idea is just to call the database n times, where n = length(word). But I would like to know if there is any kind of 'short-circuit OR' in SQL -- MySQL/MariaDB, to be precise.
Example
DB has 'w', 'word', 'wording', want to search by 'word' and retrieve 'word' only.
DB has 'z', 'zab', 'zac', 'ze', 'zeb' want to search by 'za' and get 'zab'