表objects
MySQL數據數組的鍵名獲取與UNION
id name is_animal
-----------------------
1 dog 1
2 cat 1
3 chair 0
4 rabbit 1
查詢
(SELECT name AS animal_name FROM objects WHERE is_animal = 1)
UNION
(SELECT name AS object_name FROM objects WHERE is_animal = 0)
,結果
[animal_name] => dog
[animal_name] => cat
[animal_name] => rabbit
[animal_name] => chair // expected: [object_name] => chair
我已經在第二使用AS
SELECT,爲什麼它會返回animal_name
而不是object_name
?
你想要兩個不同的領域(animal_name/OBJECT_NAME)? –
@Grisha是的,椅子應該有一個關鍵名'object_name'和其他人'animal_name' – user1643156