我正在使用無法控制數據庫列名稱的CMS系統。和我有兩個相關的表:我如何使用別名從另一個表中選擇別名?
表:內容
+------------+----------+----------+----------+----------+
| content_id | column_1 | column_2 | column_3 | column_4 |
+------------+----------+----------+----------+----------+
| 1 | stuff | junk | text | info |
| 2 | trash | blah | what | bio |
+------------+----------+----------+----------+----------+
表的欄
+------------+-------------+
| column_id | column_name |
+------------+-------------+
| 1 | good_text |
| 2 | bad_text |
| 3 | blue_text |
| 4 | red_text |
+------------+-------------+
我想在這裏做什麼,從第一個表中選擇,但選擇列作爲第二個表中的column_name。所以,我的結果會是什麼樣子:
+------------+-----------+----------+-----------+----------+
| content_id | good_text | bad_text | blue_text | red_text |
+------------+-----------+----------+-----------+----------+
| 1 | stuff | junk | text | info |
| 2 | trash | blah | what | bio |
+------------+-----------+----------+-----------+----------+