MySQL CASE WHEN 根據一個表的字段值不一樣關聯查詢兩張不一樣的表

Control Flow Functionsmysql

• CASE value WHEN [compare_value] THEN result [WHEN [compare_value] THEN result ...] [ELSE result] ENDsql

SELECT * FROM table LEFT JOIN x ON x.id = table.id LEFT JOIN (SELECT id, CASE table.x WHEN 1 THEN "tablea" WHEN 2 THEN "tableb" WHEN 3 THEN "tablec" END FROM tablex) AS tmpe ON tmpe.id = table.n WHERE table.id = "hello" LIMIT 1;
相關文章
相關標籤/搜索