Link to home
Start Free TrialLog in
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/questions/27722365/How-to-Query-Distinct-Values-Only-Different.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!
ASKER CERTIFIED SOLUTION
Avatar of ralmada
ralmada
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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
Avatar of zberg007
zberg007

ASKER

This worked great for my purposes. Thanks!