表保存內容的信息 - content
:複雜MySQL的加入與替換列
+----------+-------------+-------------------+--------------------------------+
| (int) id | (int) title | (int) description | (string) tags |
+----------+-------------+-------------------+--------------------------------+
| 1 | 12 | 18 | super, awesome, must-see |
+-----------------------------------------------------------------------------+
| 4 | 25 | 26 | randomness, funny-stuff, cool |
+-----------------------------------------------------------------------------+
表中包含翻譯信息 - translations
:
+-----------+---------------------------------+----------------+
| (int) tid | (text) value | (varchar) code |
+-----------+---------------------------------+----------------+
| 12 | Super-awesome-mustsee | en |
+--------------------------------------------------------------+
| 18 | <here would be the description> | en |
+--------------------------------------------------------------+
| <more translation data that is not necessary for this xmpl.> |
+--------------------------------------------------------------+
我想實現的是,以取代content.title
translations.value
以及相同的描述(更多/更少數據爲不同組件(content
)表)其中content.title
匹配translations.tid
,如:
+----------+-----------------------+---------------------------------+--------------------------------+
| (int) id | (text) title | (text) description | (string) tags |
+----------+-----------------------+---------------------------------+--------------------------------+
| 1 | Super-awesome-mustsee | <here would be the description> | super, awesome, must-see |
+-----------------------------------------------------------------------------------------------------+
到目前爲止,我必須只能加入翻譯數據爲一個值......是的,聯接所不能替代的。 :|
SELECT `content` . * , `translations`.value
FROM `content`
JOIN `translations` ON `translations`.tid = `content`.title
WHERE `translations`.code = 'en'
我該如何做到這一點?
在此先感謝!
此線路:JOIN'translations' ON'translations'.tid ='content'.title似乎是錯誤的:您必須加入content.id,而不是標題... – Nanocom