Avatar of zberg007
zberg007
 asked on

How to Add in Another Column With the Data Filtered

Please review my prior question, which as been answered and closed:
https://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/Q_27722365.html

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
zberg007

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ralmada

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
or
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
Zberteoc

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

SELECT LD.Label_ID, LD.Label_Description,LL.Label_Text
            FROM   LABEL_DESCRIPTIONS LD
                            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
zberg007

ASKER
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