Results 1 to 2 of 2

Thread: sql query

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2004
    Posts
    151

    sql query

    Hi,
    I use the following code and it gave me an error message
    Server: Msg 8120, Level 16, State 1, Line 1
    Column 'sug.SENDER' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    Code:
    select sug.msgid,sug.sender from sug,mail
    where sug.msgid=mail.msgid
    group by sug.mid
    could anyone please tell me the problem of the code?


    Thanks,
    NewBie

  2. #2
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    CT
    Posts
    17,882
    All fields in the SELECT list must be in the GROUP clause:

    Code:
    select sug.msgid,sug.sender from sug,mail
    where sug.msgid=mail.msgid
    group by sug.msgid,sug.sender
    Also - I see no reason why you are joining MAIL to the QUERY - it's not being used anywhere and if MSGID is in MAIL more than once you will double/triple records in the RETURNED data.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width