lundi 16 mai 2016

SQL query giving error for join

I want to run a SQL query which is below

SELECT 
    COUNT (a.status_flag) counts, 
    a.mkey, a.to_user
FROM  
    inward_doc_tracking_hdr a
LEFT JOIN 
    user_mst b ON a.to_user = b.mkey
WHERE  
    a.to_user = 1260 AND a.status_flag = 4.

but it is not running, throwing this error:

Column 'inward_doc_tracking_hdr.Mkey' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

What's wrong here?

I am using SQL Server 2005.

Aucun commentaire:

Enregistrer un commentaire