I have a table called - tbl_emp_info in MYSQL and MSSQL(SQL server) DB with same schema and data.
I am executing following query on this data -
MYSQL Query
select count(*), name from tbl_emp_info group by dept;
MSSQL Query
select count(*), name from tbl_emp_info group by dept;
When I execute the MYSQL query, it runs and gives me result. But when I execute the MSSQL query, it gives this error
SQL Error (8120): Column 'NAME' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
Now, I understand the error and I've checked it's ref - check this out : REF
Also, In MYSQL - It would give first value for NAME in the output and ignore the rest values for NAME when it does a "group by" by DEPT.
I need to fetch same results with MSSQL as well. Please enlighten.