我有一个似乎返回意外空白行的 sql 查询。此查询与另一个表有一个右连接,但是当返回行时它返回一个空值..
SELECT e.error_id, e.user_id, e.error_title, e.error_content, e.error_answers,
e.error_votes, e.error_views, e.error_added_date, u.user_name
FROM errors e
JOIN users u
ON u.user_id=e.user_id
RIGHT JOIN answers a
ON a.error_id=e.error_id AND a.answer_accepted='1'
GROUP BY e.error_id
ORDER BY e.error_added_date DESC
此查询应该返回我一行,但它返回我预期的行和一个空白值的行.. 为什么会这样?
参赛作品
+----------------------------------------------------------------------------------------------------+
answer_id | error_id | user_id | answer_content | answer_accepted | answer_votes | answer_added_date |
1 | 3 | 1 | text | 0 | 0 | 2013-01-31 12:49:12
2 | 3 | 1 | text | 1 | 1 | 2013-01-31 12:52:29
3 | 3 | 1 | text | 0 |-1 | 2013-01-31 12:53:45
4 | 2 | 1 | text | 0 |-1 | 2013-01-31 12:53:45
+----------------------------------------------------------------------------------------------------+
结果:
+-------------------------------------------------------------------------------+
| 1 | 1 | text | 3 | 0 | 2 | 2013-01-29 16:56:20 | Mihai Matei |
|NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
+-------------------------------------------------------------------------------+