MySQL – SELECT COALESCE with Subselects Error ‘Operand Should Contain 1 Column’

coalesceMySQL

I made this query:

    SELECT 
        COALESCE(
                 (SELECT * 
                  FROM JournalEntryTitleAndContent jetc 
                  WHERE jetc.language_id = 2 
                        AND jetc.journalentry_id = 1 LIMIT 1),
                 (SELECT * 
                  FROM JournalEntryTitleAndContent jetc 
                  WHERE jetc.language_id = 1 
                        AND jetc.journalentry_id = 1 LIMIT 1),
                 (SELECT * 
                  FROM JournalEntryTitleAndContent jetc 
                  WHERE jetc.journalentry_id = 1 LIMIT 1)
                 )

Its purpose is to check if there is a row present with language_id 2 (thats the preferred language). If that is not present then the coalesce should try to find the row with the fallbacklanguage with id 1, if that returns null as well then it should return the first row it can find where journalentry_id = 1.

When I execute this statement in workbench i get Error Code 1241: Operand should contain 1 column(s)

Can i not return a row as a single value from coalesce? If not what should i use instead then? Should i use CASE or IFNULL() instead?

Thank you

Best Answer

SELECT * 
FROM JournalEntryTitleAndContent jetc 
WHERE jetc.journalentry_id = 1 
ORDER BY FIND_IN_SET(jetc.language_id, '1,2') DESC
LIMIT 1