Table: Unit
ID NAME VALUE
1 Kilo 1000
2 Mega 1000000
3 Giga 1000000000
Table: Storage
ID Title Drive_value DriveUnitID Cache_value CacheUnitID Status_ID error error_unit area
1 Seagate 100 3 400 1 2 1 1 1
2 Scansoft 250 3 80 2 1 1 2 2
Table: manufac
ID area
1 US
2 CHINA
Table: Status
ID Description
1 Blah.. Blah
2 Durka Durka
Desired goal is to have a subselect joining three tables
Something like this (below) but this syntax doesnt work
select
s.title,
t.description,
x.area,
u1.value * s.cache_value as Cache,
u2.value * s.drive_value as Drive,
u3.value * s.error_value as Error
((u4.value * s.error_value)+(u4.value * s.error_value)) as ErrorHigh
((u5.value * s.error_value)-(u5.value * s.error_value)) as ErrorHigh
from storage s
join status t on t.id = s.status_id
join manufac x on x.id = s.manufac_id
join unit u1 on s.cache_unit_id = u1.id
join unit u2 on s.drive_unit_id = u2.id
join unit u3 on s.error_unit_id = u3.id
join unit u4 on s.error_unit_id = u4.id
join unit u5 on s.error_unit_id = u5.id
This queries are semantically the same. But remember either you put the table in the join or in the from clause:
With explicit joins:
With implicit joins:
The final result is the same for the end user and the DBMS also process both query the same way, so there are no performance increment by using one or the other.
Edit:
After the requirements changed this is the query I think you’re looking for:
Example
Result:
So I guess this query is not what you really need, but should be enough to lead you in the right direction. Good luck!