0

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

Table1

and table 2

Table2

I am trying to show like this

show

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?

TBA
  • 1,921
  • 4
  • 13
  • 26
RobyRNL
  • 3
  • 3
  • Does this answer your question? [Column "invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause"](https://stackoverflow.com/questions/18258704/column-invalid-in-the-select-list-because-it-is-not-contained-in-either-an-aggr) – TBA Feb 20 '22 at 03:40
  • `"i have table Table1"` THESE ARE NOT TABLES BUT IMAGES. Hi, If you need help regarding tables then please provide queries to CREATE the tables and insert sample data. In addition please provide the expected result SET according to the sample data. – Ronen Ariely Feb 20 '22 at 03:46

1 Answers1

0

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