sql - Why cant I use GROUP BY in this Query -


when executed following query in ms sql management studio produced error.

query:

select  u.username, r.rolename user u join userrole ur on ur.userid = u.userid join role r on r.roleid = ur.roleid group r.rolename 

error:

msg 8120, level 16, state 1, line 2 column 'user.username' invalid in select list because not contained in either aggregate function or group clause.

its been while had used sql , supposed basic command. still cant figure out reason.

note:

there no error if use

group r.rolename, u.username

this demonstrates single-value rule, prohibits undefined results when run group by query, , include columns in select-list neither part of grouping criteria, nor appear in aggregate functions (sum, min, max, etc.). hope u understand.

group by

i dont know may want this..

select distinct u.username, r.rolename user u join userrole ur on ur.userid = u.userid join role r on r.roleid = ur.roleid 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -