I got a problem with sql. i dunno why access and sql server keep show me the error.
I use phpmyadmin, but no issue.
I have 1 table. My table name is t_data
ID MasterCode DetailCode Description Item Status
1 1 1.1 Resources Meat 1
2 1 1.1 Resources Meat 1
3 1 1.1 Resources Meat 1
4 1 1.1 Resources Meat 1
5 3 3.1 Utility oil 1
6 2 2.1 Transport BBM 1
I want to query that table and want the result looks like:
MasterCode Description
1 Resources
2 Utility
3 Transport
And here is my sql syntax
"select MasterCode, Description from t_data group by Description order by MasterCode"
Usually i just use that sql syntax, and i can get what i want. But now i can’t.
you tried to execute a query which does not include the specified expression as an aggregate function.
I got that error if i’m using access and sql server. If i’m using phpmyadmin in XAMPP, it working fine. But I don’t want to use phpmyadmin. I want to use access or sql server.
I already search on google about that error. and i change my sql into this.
"select count(*), Description from t_data group by Description "
and"select a.categoryMaster, b.categoryDesc from t_category a inner join t_category b on a.categoryDetail = b.categoryDetail"
not solved my problem, because i want to get the MasterCode too.
any solution? thanks.
You can use
DISTINCT:See SQL Fiddle with Demo
Or you might be able to use an aggregate function like
MAX():See SQL Fiddle with Demo