Suppose I have this table: named = the_table whose structure is:
postgreSQL:
create table the_table (col3 SERIAL, col2 varchar, col1 varchar, PRIMARY KEY(col3));
MySQL:
create table the_table ( col3 INT NOT NULL AUTO_INCREMENT PRIMARY KEY, col2 varchar(20), col1 varchar(20) )
Then I inserted the table:
INSERT INTO the_table (col2,col1) VALUES
('x','a'),
('x','b'),
('y','c'),
('y','d'),
('z','e'),
('z','f');
Now the table looks like this:
col3 | col2 | col1
------+------+------
1 | x | a
2 | x | b
3 | y | c
4 | y | d
5 | z | e
6 | z | f
When I do this query:
select * from the_table group by col2
then in mysql I get:
1 x a
3 y c
5 z e
and in postgreSQL, I am getting error:
ERROR: column "the_table.col3" must appear in the GROUP BY clause or be used in an aggregate function
LINE 1: select * from the_table group by col2;
My Questions:
What does this error mean? What is aggregate function ?
When it works in MySQL , why can't it work in postgreSQL ?