DAN212
DAN212

Reputation: 51

SQL - Your query does not include the specified expression as part of an aggregate function

I'm trying to display data from two tables in ms access using an SQL command. I want to display the data title, forename, surname, name, type and breed. And group it by surname and name. I created the SQL command below which works fine on phpmyadmin but I get and error on ms access which is displayed below the SQL command. Any help is appreciated.

SELECT Title, Forename, Surname, Name, Type, Breed
FROM owner, pet
GROUP BY Surname, Name;

Error

Your query does not include the specified expression 'Title' as part of an aggregate function.

Upvotes: 0

Views: 13779

Answers (2)

marlan
marlan

Reputation: 1485

Any field in a group by query must either be in the group by clause, or be in an agrigation function. When field is of String type, you can use MIN(), or MAX() functions, that will give you the desired results:

SELECT min(Title), min(Forename), Surname, Name, Min(Type), Min(Breed)
FROM owner, pet
GROUP BY Surname, Name;

Upvotes: 4

John Pasquet
John Pasquet

Reputation: 1842

When using the GROUP BY Statement, you can only include the grouped columns along with SUM, COUNT and things like that. These are the "aggregate functions".

In your case, Title is not one of the GROUP BY Parameters.

So, if these other columns are the same for each individual, go ahead and include them in the GROUP BY parameter list.

Upvotes: 0

Related Questions