can you list the ways to join values on a sql query twice?

You would just join twice:

select c.*, f1.fuel_label, f2.fuel_label as secondary_fuel_label
from cars c left join
     fuel_types f1
     on c.fuel_id = f1.fuel_id left join
     fuel_types f2
     on c.fuel_id = f1.secondary_fuel_id ;

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.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top