带有GROUP BY和WHERE子句的INNER JOIN错误 [英] Error for INNER JOIN with GROUP BY and WHERE clause
本文介绍了带有GROUP BY和WHERE子句的INNER JOIN错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这些桌子
学生:
id Name
-------------------
1 john
2 carlos
3 zoya
4 arab
5 amir
以及
电子邮件:
id email student_id
--------------------------
1 a@mail.com 1
2 b@mail.com 2
3 c@mail.com 2
4 d@mail.com 3
5 e@mail.com 4
我正在使用此查询,并且在查询第4行上使用sql错误,
I'm using this query and it's getting Using sql error on query line 4
,
SELECT * FROM student
INNER JOIN email
ON student.id = email.student_id
GROUP BY student.id
WHERE student.id = 2
我在SQL方面没有太多经验。
I don't have much experience in SQL.
推荐答案
首先, GROUP BY
总是放在 WHERE $ c之后$ c>子句。
其次,i如果您正在使用 GROUP BY
子句,则应该对字段使用聚合函数,这些函数不包含在其中,但仍存在于 SELECT中
子句,或 GROUP BY
包含在 SELECT
中的整个列包。
Firstly, GROUP BY
always goes after the WHERE
clause.
Secondly, if you are using the GROUP BY
clause you should either use aggregate functions for the fields, that are not contained in it and still are present in the SELECT
clause, or GROUP BY
the whole pack of columns contained in the SELECT
.
这篇关于带有GROUP BY和WHERE子句的INNER JOIN错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文