views:

17

answers:

0

I have 8 table that contain different specific value for computer peripheral they are glpi_device_ram, glpi_device_hdd, glpi_device_gfxcard, glpi_device_sndcard. Each table has the same designation column in each table that contain device name. i have table glpi_computer_device that contain FK_device that contain id for each 8 table above and device type column that help me decide which table(from 8 table above) should i associate with FK_device to get designation column. I have create sql syntax but not work. I need to know whether selecting table in FROM clause using CASE clause is allowed? Here is my code

 SELECT CASE device_type
          WHEN "1" THEN "Casing"
          WHEN "2" THEN "Processor"
          WHEN "3" THEN "RAM"
          WHEN "4" THEN "Harddisk"
          WHEN "5" THEN "Network Card"
          WHEN "6" THEN "Drive"
          WHEN "7" THEN "UNKNOWN"
          WHEN "8" THEN "Graphic Card"
          WHEN "9" THEN "Sound Card"
          WHEN "10" THEN "Other device"
        END AS devicetype, 
        CASE device_type
          WHEN "1" THEN "--"
          WHEN "2" THEN "Frequency"
          WHEN "3" THEN "Size"
          WHEN "4" THEN "Capacity"
          WHEN "5" THEN "Mac Address"
          WHEN "6" THEN "Memory Size"
          WHEN "7" THEN "--"
          WHEN "8" THEN "Memory Size"
          WHEN "9" THEN "--"
          WHEN "10" THEN "--"
        END AS secificity_type,
        specificity, 
        (SELECT c.designation
           FROM (SELECT CASE cd.device_type
                          WHEN "2" THEN "glpi_device_processor"
                          WHEN "3" THEN "glpi_device_ram"
                          WHEN "4" THEN "glpi_device_hdd"
                          WHEN "5" THEN "glpi_device_iface"
                          WHEN "6" THEN "glpi_device_drive"
                          WHEN "8" THEN "glpi_device_gfxcard"
                          WHEN "9" THEN "glpi_device_sndcard"
                          WHEN "10" THEN "glpi_device_pci"
                        END
                   FROM glpi_computer_device cd 
                  WHERE cd.ID = ID ) AS c
          WHERE c.ID=FK_device)
  FROM `glpi_computer_device` 
 WHERE FK_computers = 1