D
D
Dmitry2016-04-20 11:27:47
Oracle
Dmitry, 2016-04-20 11:27:47

How to display NULL if there are no rows?

Experienced comrades, we need your help. There is the following scheme:
aa46e9971cfd42a3a9181c8de79bca09.png
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'

Example data:
table_main :
id  |  val
-----------
1      100
2      150

table_ext ;
id  |  ext_name     |  val
---------------------------
1	ADD_ATTR     200
1	ADD_VAL      5
2       ADD_VAL      10

In the event that the condition 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?
Thanks in advance.
PS LEFT JOIN does not work in this query

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2016-04-20
@kashamalasha

LEFT JOIN `table_ext` AS `te` ON `te`.`id` = `t`.`id` AND `te`.`ext_name` = 'ADD_ATTR'

A
Artem Klimenko, 2016-04-20
@aklim007

LEFT JOIN

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question