Reputation: 814
I am writing a SQL Server statement to draw some data from 2 tables like this:-
$resume_full_name = "select * from [user]
left join [department]
on [user].[departid] = [department].[departid]
where id = '$value'
order by [department].[departid] DESC";
and it works properly. However, when I try to add GROUP BY [department].[departid]
, wherever this phase I put, it gives error.
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near the keyword 'GROUP'. (severity 15) in D:\project\true2\admin\page\ur\list.php on line 86 Warning: mssql_query() [function.mssql-query]: Query failed in D:\project\true2\admin\page\ur\list.php on line 86 Warning: mssql_fetch_array(): supplied argument is not a valid MS SQL-result resource in D:\project\true2\admin\page\ur\list.php on line 88
Actually, do mssql suppport Group By
? if not, how can we group things together? Thanks
Upvotes: 0
Views: 1043
Reputation: 15320
Yes it does support GROUP BY
, but you cannot SELECT *
at the top, you have to apply an aggregate function (e.g. SUM
or AVG
) to some other field on which the aggregate of grouped rows will be shown.
Upvotes: 3