I've got these tables
student:
id Name
-------------------
1 john
2 carlos
3 zoya
4 arab
5 amir
and,
email:
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
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
I don't have much experience in SQL.
Firstly,
GROUP BY
always goes after theWHERE
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 theSELECT
clause, orGROUP BY
the whole pack of columns contained in theSELECT
.