lundi 2 novembre 2015

Getting error by using IF with JOIN in SELECT mysql

I am new to IF statement in mysql query. I follow this answer to write my own query.

Basically I am trying to select data if an attribute in Base table "Peripheral" then join Base table with Peripheral table, Else join Base table with other table.

Following query which I have tried to build:

SELECT * FROM CC_FIRMWARE 

INNER JOIN 

IF(CC_FIRMWARE.Device_Class = "Peripheral", 
    RC_Peripheral_Type ON RC_Peripheral_Type.Id = CC_FIRMWARE.Device_Type_Id, 
    RC_Box_Type ON RC_Box_Type.Id = CC_FIRMWARE.Device_Type_Id)

WHERE CC_FIRMWAER.Id = 4;

I am getting syntax error. unexpected 'IF' (if)

Aucun commentaire:

Enregistrer un commentaire