I have two tables for car information’s to identify which type of engine they have. Therefore I need a second table where all the special equipment of the car is listed. Table 1 distinguishes between Battery and No-Battery. With the key of the special equipment out of table2 it can be identified if the "No-Battery" Cars are Hybrids or Combustion Engine Cars. If they have the special Equipment "ABC" Key, they are Hybrid Cars. If not they are Combustion Cars.
Table 1:
> ID |Car |Engine |
> 1 |RED |BATTERY |
> 2 |YELLOW |NO-BATTERY |
> 3 |BLUE |NO-BATTERY |
Table 2:
-ID-|SPECIAL EQUIPMENT
1 |AAA
1 |BBB
1 |CCC
2 |ABC
2 |BBB
2 |CCC
3 |ABC
3 |BBB
3 |CCC
THE SQL Query is:
SELECT DISTINCT mytable.id, mytable.car, mytable.engine
FROM
(SELECT table1.id, table1.car, table1.engine, table1.type,
CASE WHEN table1.type = 'Battery' THEN 'BEV'
WHEN table1.type = 'No-Battery' THEN (CASE WHEN special Equipment = 'ABC' THEN 'HYBRID'
ELSE 'COMBUSTION' END)
END AS engine
FROM table1
INNER JOIN table 2 key ON table1.id = table2.id
WHERE (cars.id = 2 )
)t;
The SQL Code Returns for CAR ID 2 --> 2 Columns, one time with engine type Hybrid and one time with engine type combustion.
RESULT (Current):
> ID |Car |type |engine
> 2 |YELLOW |NO-BATTERY |HYBRID
> 2 |YELLOW |NO- BATTERY |COMBUSTION
I WANT TO SHOW:
> ID |Car |type |engine
> 2 |YELLOW |NO-BATTERY |HYBRID
The Result with Combustion is wrong but is displayed... how can i just get one right return?