I have a request
SELECT IF ( EXISTS ( SELECT name_short, name_full, ... FROM (SELECT ... FROM ... WHERE ... GROUP BY ... ORDER BY ...) a UNION ALL SELECT name_short, name_full, ... FROM (SELECT ... FROM ... WHERE ... GROUP BY ... ORDER BY ...) b ) = 0, 'empty set', 'not empty set' ) ; It works correctly, and if the query inside the EXISTS function returns an empty string, it displays the message 'empty set ', otherwise the string 'not empty set' . I want to get the values of the name_short and name_full fields if the query inside the EXISTS function returns data (and not an empty string). How can this be done without duplicating the code?