我有以下MySQL表不需要NULL值导致
tbl_pet_types:
+----------+-------------+
| pet | type |
+----------+-------------+
| cat | mammal |
| dog | mammal |
| goldfish | fish |
| goldfish | seacreature |
| snake | reptile |
+----------+-------------+
我有这样的查询选择一个青蛙和它的类型:
SELECT types.pet,
group_concat(types.type separator ', ') AS type
FROM tbl_pet_types types
WHERE types.pet IN ('frog', 'mouse', 'goldfish');
由于青蛙和鼠标不是tbl_pet_types,返回的结果是:
+----------+-------------------+
| pet | type |
+----------+-------------------+
| goldfish | fish, seacreature |
+----------+-------------------+
但我想:
+----------+------------------+
| pet | type |
+==========+==================+
| frog | NULL |
+----------+------------------+
| mouse | NULL |
+----------+------------------+
| goldfish | fish,seacreature |
+----------+------------------+
我怎样才能改变我的查询得到我想要的结果吗?
尝试IFNULL()函数 – money