I have two tables that look like these:
users:
id int unsigned auto_increment,
primary key(id),
[...]
product:
id int unsigned auto_increment,
seller id int unsigned auto_increment,
primary key(id),
foreign key(seller) references users(id)
[...]
I want to have a list of users with all of their attributes and the amount of products each user has. I tried the following:
select u.id, [...], count(p.id) from users u, products p where p.seller=u.id and [...]
This, however gives me the following error:
ERROR 1140 (42000): In aggregated query without GROUP BY, expression #1 of SELECT list contains nonaggregated column 'db.u.id'; this is incompatible with sql_mode=only_full_group_by
What would be the proper way of accomplishing the wanted result? And why does this not work?