2013-10-18 60 views
0

我想通過查找另一個表中的值來創建列別名。這是我正在嘗試的MySQL,但不斷收到語法錯誤 - 任何幫助將不勝感激。從選擇語句創建列名別名

SELECT 
product_code, 
bField1 as (select [label_value] from [labels] where [field_value]='bField1'), 
bField2 as (select [label_value] from [labels] where [field_value]='bField2'), 
.... 
FROM products 
+2

它應該是相反的' as ' –

+0

你確定這是MySQL嗎? – Strawberry

+0

這是如何編寫示例代碼...它是別名我試圖使動態不是表達式/字段值 – user2894377

回答

2

嘗試爲便接踵而來:

SELECT 
product_code, 
(select [label_value] from [labels] where [field_value]='bField1') as bField1, 
(select [label_value] from [labels] where [field_value]='bField2') as bField2, 
.... 
FROM products 
+0

我仍然希望只返回列別名的bField1的列需要從另一個表中獲取。你是說MySQL與SQL相反,並且別名在語法之前出現在列之前? – user2894377