0
MySQL查詢:Mysql的CASE WHEN JOIN語句錯誤
SELECT *
FROM `pet_info` LEFT JOIN
`lostpets`
ON `pet_info`.`id` = `lostpets`.`petid` LEFT JOIN
`pet_images`
ON `pet_info`.`id` = `pet_images`.`petid`
CASE WHEN `pet_info`.`pet_cat` = 2
THEN LEFT JOIN `cat_breeds`
ON `cat_breeds`.`id` = `pet_info`.`pet_breed`
WHEN `pet_info`.`pet_cat` = 1
THEN LEFT JOIN `dog_breeds`
ON `dog_breeds`.`id` = `pet_info`.`pet_breed`
WHERE `pet_info`.`pet_user_id` = 581
錯誤:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'CASE WHEN `pet_info`.`pet_cat` = 2 THEN LEFT JOIN `cat_breeds` ON `cat_breeds`.`' at line 1
我怎麼能解決錯誤?錯誤在哪裏?請幫幫我。
這根本不是'CASE'所做的。它是一個標量表達式,它在'FROM'子句中返回一個值,而不是一個條件構造。 –