Avatar of zberg007
 asked on

How to Add in Another Column With the Data Filtered

Please review my prior question, which as been answered and closed:

Now, I just want to add back in one more column... the original LL.Label_Text, so that I can see this value in the returned results. I tried adding it in the select statement, but I get this error: Msg 8120, Level 16, State 1, Line 1
Column 'LABEL_LANGUAGES.LABEL_TEXT' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

When I add it to the Group By clause, I get all the results returned from my table (306) rather than my filtered data.

Thanks Experts!
Microsoft SQL ServerMicrosoft SQL Server 2005

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

Add the column in both the GROUP BY clause and in the SELECT list:

SELECT LD.Label_ID, LD.Label_Description,LL.Label_Text
                            INNER JOIN LABEL_LANGUAGES  LL  ON LL.Label_ID = LD.Label_ID
            where LL.Language_ID = 1 OR LL.Language_ID = 5
group by LD.Label_ID, LD.Label_Description,LL.Label_Text
having Count(1) = 1
            order by LL.Label_ID

This worked great for my purposes. Thanks!
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck