Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 GROUP BY question

Author  Topic 

evanburen
Posting Yak Master

167 Posts

Posted - 2011-03-01 : 21:03:45
How I can add ID to this SELECT statement but not GROUP BY this value? Every ID is unique so it never returns any records.

SELECT
ID,
SSN,
COUNT(*) AS VACount
FROM
v_MyVAApps

GROUP BY
ID,
SSN
HAVING
COUNT(*) > 1
ORDER BY
SSN

evanburen
Posting Yak Master

167 Posts

Posted - 2011-03-01 : 21:31:45
Hi

This works for me

SELECT
MAX(ID),
SSN,
COUNT(*) AS VACount
FROM
v_MyVAApps

GROUP BY
SSN
HAVING
COUNT(*) > 1
ORDER BY
SSN
Go to Top of Page

jcelko
Esteemed SQL Purist

547 Posts

Posted - 2011-03-02 : 22:26:12
Please post real DDL. Learn to use ISO-11179 rules for the data element names, avoid needless dialect and use ISO-8601 temporal formats, codes and so forth. People cannot read your mind, so post your code and clear specs if you really want help.

Rows are not records.

What you asked makes no sense. What value for your vague generic "id" did you expect to see?


--CELKO--
Books in Celko Series for Morgan-Kaufmann Publishing
Analytics and OLAP in SQL
Data and Databases: Concepts in Practice
Data, Measurements and Standards in SQL
SQL for Smarties
SQL Programming Style
SQL Puzzles and Answers
Thinking in Sets
Trees and Hierarchies in SQL
Go to Top of Page
   

- Advertisement -