Column 'Tabel1.Nama' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
I have two tables, table 1
and table 2
I am trying to show like this
my Query:
SELECT Tabel1.NIK, Tabel1.Nama, AVG(Table2.Nilai) AS RataRata FROM
Tabel1, Table2 WHERE Tabel1.NIK = Table2.NIK GROUP BY Tabel1.NIK
but I have an error like this Column 'Tabel1.Nama' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
anyone can fix my Query?
CodePudding user response:
Add Nama to the group by
SELECT Tabel1.NIK, Tabel1.Nama, AVG(Table2.Nilai) AS RataRata FROM Tabel1, Table2 WHERE Tabel1.NIK = Table2.NIK GROUP BY Tabel1.NIK, Tabel1.Nama
Or remove Nama from the select
SELECT Tabel1.NIK, AVG(Table2.Nilai) AS RataRata FROM Tabel1, Table2 WHERE Tabel1.NIK = Table2.NIK GROUP BY Tabel1.NIK