SHARE
TWEET

Untitled

a guest Jan 12th, 2017 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SELECT cupboards.cupboard_id, cupboards.name, cupboards.capacity, dist.item_type_id, item_types.name, locations.coordinates FROM cupboards INNER JOIN
  2. (SELECT DISTINCT cupboard_items.item_type_id, cupboard_id FROM cupboard_items) AS dist
  3. ON cupboards.cupboard_id = dist.cupboard_id
  4. INNER JOIN item_types ON dist.item_type_id = item_types.item_type_id
  5. INNER JOIN locations ON locations.location_id = cupboards.location_id;
  6.    
  7. $result = DB::table('cupboards')
  8.             ->select(DB::raw('cupboards.cupboard_id, cupboards.name, cupboards.capacity, dist.item_type_id, item_types.name, locations.coordinates'))
  9.             ->join(DB::raw('SELECT DISTINCT cupboard_items.item_type_id, cupboard_id FROM cupboard_items'))
  10.             ->join('item_types', 'dist.item_type_id', '=', 'cupboard.item_type_id')
  11.             ->join('locations', 'locations.location_id', '=', 'cupboards.location_id')
  12.             ->get();
RAW Paste Data
Top