I would like to be able to bring a default value after executing a query in case it does not bring any rows. I have tried a bit of everything, COALESCE, NULLIF, NOT EXISTS, EXISTS, etc.
I do not know if someone has already tried it before to see if you could do me the favor of helping me with this.
SQL:
SELECT CASE
WHEN EXISTS(SELECT tabla1.tbl1_campo1
FROM tabla1
WHERE tabla1.campo2 = 'EXAMPLE'
AND tabla1.campo1 = tabla2.campo1_tbl1 ) THEN '1'::CHAR(1)
ELSE '0'::CHAR(1)
END
FROM tabla2, tabla3
WHERE tabla2.campo1 = 138239
AND tabla2.campo1_tbl3 = tabla3.campo1
AND (split_part(tabla3.campo2, '-', 1))::CHAR(2) IN ('16', '17', '18')
If I execute it as it is, it results in zero rows and I would like it to show at least one row / field, (defined by me), in order to make a comparison:
I thank you in advance for all the help you can give me with the matter, since I have been trying for several days to find an answer to this problem and I have not been able to find it yet.