Skip to content
Advertisement

In Oracle SQL is there a way to join on a value twice?

Lets say I have two tables, with the following columns:

cars

fuel_types

In this case fuel_id and secondary fuel_id both refer to the fuel_types table.

Is it possible to include both labels in an inner join? I want to join on the fuel_id but I want to be able to have the fuel label twice as a new column. So the join would be something like:

In this case I would have created the secondary_fuel_label column.

Is this possible to do in SQL with joins? Is there another way to accomplish this?

Advertisement

Answer

You would just join twice:

The key point here is to use table aliases, so you can distinguish between the two table references to fuel_types.

Note that this uses left join to be sure that rows are returned even if one of the ids are missing.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement