Cette requête devrait aussi faire le job, je pense :

SELECT 
  IF(COUNT(*) > 0, macolonne2, 'ABC')
FROM ma_table
  WHERE macolonne1 = 123
  AND macolonne2 IS NOT NULL
LIMIT 1 

Bonne journée

Le mercredi 25 mai 2022 à 08:49 +0200, Olivier a écrit :
> Voici la réponse de Dethegeek:
> 
> CREATE TABLE `ma_table` (
> `id` INT(10) NOT NULL,
> `macolonne1` INT(10) NOT NULL,
> `macolonne2` VARCHAR(50) NULL DEFAULT NULL
> PRIMARY KEY (`id`)
> );
> 
> SELECT
>     if (
>         (
>             SELECT
>                 COUNT(*)
>             FROM
>                 ma_table
>             WHERE
>                 macolonne1 = 123
>                 AND NOT ISNULL(macolonne2)
>         ) = 0,
>         'ABC',
>         (
>             select
>                 macolonne2
>             from
>                 ma_table
>             where
>                 macolonne1 = 123
>                 and not isnull(macolonne2)
>         )
>     )
> 
> 
> > > 

Répondre à