mysql if exists return the record value instead of regular output

I want a select that if/exists it returns the ‘link’ value instead of regular output.
so instead of ‘1’ it returns the ‘link’

Is that possible?

        SELECT link FROM modules WHERE module='license'
    ), 1, '/dashboard/'

>Solution :

Use aggregation with MAX() (or MIN()):

SELECT COALESCE(MAX(link), '/dashboard/') link
FROM modules 
WHERE module = 'license';

If that specific link does not exist in modules then MAX() will return null in which case COALESCE() will return '/dashboard/'.

Leave a Reply