id key code description
------------------------------
1 1 misc miscellaneous
2 1 med medicine
其他表:
id code description
------------------------
1 misc1 miscellaneous
2 misc1 miscellaneous
醫學表:
id code description
---------------------------
1 medicine1 medicine
2 medicine1 medicine
我有這個表結構;我的主表是Item
表,我想根據主表中的列值將主表與其他表聯接起來。確定要加入的表的列是code
。如果代碼是misc
加入misc table
如果值是med
加入medicine table
。
我知道表的基本JOIN
像
SELECT *
FROM item
INNER JOIN miscellaneous ON item.key = miscellaneous.id
但我不知道如何加入時,有將指向哪個表JOIN
這是真正的有線結合其他&醫學表列!你實際上想要達到的是什麼? – Rahul
能夠根據主表中一列的值加入表格。我有一個代碼列會告訴在我的例子中加入哪個表,如果代碼是misc JOIN與雜項表,但如果代碼是MED JOIN與藥物表@Rahul – Martin
一些條件連接的選項[條件連接](https ://sqloverover.com/questions/26518526/conditional-join-statement-sql-server) – SQLAndOtherStuffGuy