I am struggling to use the query builder to create inner joins between my tables. I have three tables with the following relationships:
aircraft_classes 1:m aircraft_types m:1 brands
I am trying to construct a query where given an aircraft class, I can retrieve a list of brands. The following SQL query works correctly:
SELECT * FROM brands
INNER JOIN aircraft_types ON brands.id = aircraft_types.brand_id
INNER JOIN aircraft_classes ON aircraft_types.aircraft_class_id = aircraft_classes.id
WHERE aircraftClassID = $class
I currently have:
$brands = DB::table('brands')
->join('aircraft_types', 'brands.id', '=', 'aircraft_types.brand_id')
->join('aircraft_classes', 'aircraft_types.aircraft_class_id', '=', 'aircraft_classes.id')
->where('aircraft_classes.id', '=', $class)
->get(array('brands.id', 'brands.brand_name'));
However, this will return multiple instances of the same brand. I am struggling to create an inner join between the tables so that a brand is only returned once.
Where am I going wrong?