title: SQL query using lookup table values as columns
body: <p>I have 3 tables: Device, Service, DeviceXService</p>
  
  <p>Table (Device) has a list of devices and fields associated to the devices such as serial number device name etc.</p>
  
  <pre>
  DeviceID | Device Name | SerialNumber
  1        | iPhone      | 2352532533
  2        | iPad        | 2345435435
  3        | android     | 2532532656
  </pre>
  
  <p>Table (Service) is a lookup table that has a list of services that can be used on devices such as email, internet, texting etc.</p>
  
  <pre>
  ServiceID  | ServiceName
  1          | email
  2          | internet
  3          | texting
  </pre>
  
  <p>Table (DeviceXService) is a cross-reference table that has a record linking devices to services and the status of those devices.  </p>
  
  <p>For example.</p>
  
  <pre>
  DeviceID    | ServiceID   | Status
  --------------------------------------
  1(iPhone)   | 1(email)    | requested
  2(ipad)     | 2(internet) | Approved
  1(iPhone)   | 3(texting)  | Approved
  3(android)  | 3(texting)  | approved
  </pre>
  
  <p><strong>What I would like to do is create a query that would return all the devices FROM the Devices table, but also create a column for each type of service that exists FROM the Service table and return the status of each service for each device FROM the DeviceXService cross-reference table as one table.</strong></p>
  
  <p>example:</p>
  
  <pre>
  Device ID | Device Name | Device Serial No | email    |  texting   |  internet
  --------------------------------------------------------------------------------
      1     | iphone      | 2352532533       | requested|  approved  |  null
      2     | ipad        | 2345435435       | null     |  null      |  approved
      3     | android     | 2532532656       | null     |  null      |  approved
  </pre>
  
  <p>Note: null is if the device doesn't have a record for the service in the DeviceXService cross-reference table</p>
  
  <p>I apologize if I'm not explaining this very well but that may be why I'm having such a hard time trying to find an example of something similar.  Any help would be greatly appreciated!</p>