You cannot use the state
alias. You have to repeat your IFNULL()
expression:
... CONCAT(a, aa, IFNULL((SELECT p.name FROM p WHERE p.id = x.name), 'N.A.'))
In addition, I believe you mean CONCAT()
instead of CONCATE()
. Also note that N.A.
should be wrapped in single quotes: 'N.A.'
.
Test case:
SELECT CONCAT('1-', '2-', IFNULL((SELECT NULL), 'N.A.'));
+---------------------------------------------------+
| CONCAT('1-', '2-', IFNULL((SELECT NULL), 'N.A.')) |
+---------------------------------------------------+
| 1-2-N.A. |
+---------------------------------------------------+
1 row in set (0.00 sec)
SELECT CONCAT('1-', '2-', IFNULL((SELECT 3), 'N.A.'));
+------------------------------------------------+
| CONCAT('1-', '2-', IFNULL((SELECT 3), 'N.A.')) |
+------------------------------------------------+
| 1-2-3 |
+------------------------------------------------+
1 row in set (0.00 sec)