W
W
WayMax2017-09-01 10:08:43
SQL
WayMax, 2017-09-01 10:08:43

What SQL query will allow you to get such a selection?

There is a database of the form:
41836b826df04d5fbb6ce9e2173bcd35.png
With data:
d67f74c76668445cafb19c989878b91a.png
Tables PC, Monitor, Printer, respectively, are filled with the values ​​indicated on the last screen.
What SQL query can be used to get such a selection:
b7eafb654bc24e538398e68ff096253b.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Serg, 2017-09-01
@WayMax

If the assumption is correct that only one id_* in Task has a non-null value, then something like this (a head-on solution, it can be more elegant)
select value, (case
when id_pc is not null then (select value from PC where id=id_pc )
when id_monitor is not null then (select value from Monitor where id=id_monitor)
when id_printer is not null then (select value from Printer where id=id_printer)
end) as res from Task
order by id;
If the assumption is not true, then just the condition in the case will be more difficult

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question