Answer the question
In order to leave comments, you need to log in
How to display NULL if there are no rows?
Experienced comrades, we need your help. There is the following scheme:
There is a request:
SELECT t.id AS "ID",
t.val AS "VALUE",
te.ext_val AS "EXT_VALUE",
t.val * 2,2 AS "RATED VALUE"
FROM table_main t
JOIN table_ext te ON t.id = te.id
WHERE t.id = &id
AND t.val > 0
AND te.ext_name = 'ADD_ATTR'
id | val
-----------
1 100
2 150
id | ext_name | val
---------------------------
1 ADD_ATTR 200
1 ADD_VAL 5
2 ADD_VAL 10
te.ext_name = 'ADD_ATTR'
is not met, i.e. there are no such records, the query returns an empty set. How can I change the query so that it fills in a field te.ext_val AS "EXT_VALUE"
in the resulting table as NULL in this case? Answer the question
In order to leave comments, you need to log in
LEFT JOIN `table_ext` AS `te` ON `te`.`id` = `t`.`id` AND `te`.`ext_name` = 'ADD_ATTR'
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question