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.
| Author |
Topic |
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-03-12 : 00:11:09
|
| I am trying to pull up the whole table based on count(). I can do it where it pulls up what I am counting, but how do I get the rest of the info to show?This will return the counted rows:SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) >2How can I do it so that it shows every column? This gives an error "Incorrect syntax near the keyword 'SELECT'."select * from GlobalDBAServer.dbo.FileGroups where SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) > 2Putting the second SELECT in () causes an error at ")".really, I only want 2 more columns (logical & physical) but I don't want them as part of the count---------------------------Working until "the morning sun sets the midnight sky on fire"! |
|
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2009-03-12 : 00:53:29
|
| select "all_column_name" from GlobalDBAServer.dbo.FileGroups where SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by "all_column_name" having count(*) > 2 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-12 : 02:11:20
|
quote: Originally posted by shaggy select "all_column_name" from GlobalDBAServer.dbo.FileGroups where SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by "all_column_name" having count(*) > 2
IncorrectMadhivananFailing to plan is Planning to fail |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-03-12 : 02:12:21
|
quote: Originally posted by GRAYWOLF I am trying to pull up the whole table based on count(). I can do it where it pulls up what I am counting, but how do I get the rest of the info to show?This will return the counted rows:SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) >2How can I do it so that it shows every column? This gives an error "Incorrect syntax near the keyword 'SELECT'."select * from GlobalDBAServer.dbo.FileGroups where SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) > 2Putting the second SELECT in () causes an error at ")".really, I only want 2 more columns (logical & physical) but I don't want them as part of the count---------------------------Working until "the morning sun sets the midnight sky on fire"!
TrySELECT f.* FROM GlobalDBAServer.dbo.FileGroups as f inner join ( SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) > 2) as t on f.[server]=t.[server] and f.[database]=t.[database] MadhivananFailing to plan is Planning to fail |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-12 : 13:10:50
|
quote: Originally posted by madhivanan
quote: Originally posted by GRAYWOLF I am trying to pull up the whole table based on count(). I can do it where it pulls up what I am counting, but how do I get the rest of the info to show?This will return the counted rows:SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) >2How can I do it so that it shows every column? This gives an error "Incorrect syntax near the keyword 'SELECT'."select * from GlobalDBAServer.dbo.FileGroups where SELECT [server], [database], COUNT(*) FROM dbo.FileGroups group by [server], [database] having count(*) > 2Putting the second SELECT in () causes an error at ")".really, I only want 2 more columns (logical & physical) but I don't want them as part of the count---------------------------Working until "the morning sun sets the midnight sky on fire"!
TrySELECT f.*,t.DBCount FROM GlobalDBAServer.dbo.FileGroups as f inner join ( SELECT [server], [database], COUNT(*) AS DBCount FROM dbo.FileGroups group by [server], [database] having count(*) > 2) as t on f.[server]=t.[server] and f.[database]=t.[database] MadhivananFailing to plan is Planning to fail
small modification |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-12 : 13:12:27
|
if sql 2005 or later,just useSELECT *,COUNT(1) OVER (PARTITION BY [server], [database]) AS DBCount FROM GlobalDBAServer.dbo.FileGroups |
 |
|
|
GRAYWOLF
Posting Yak Master
106 Posts |
Posted - 2009-03-13 : 02:42:36
|
| Thanks guys.---------------------------Working until "the morning sun sets the midnight sky on fire"! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-03-13 : 12:47:28
|
| welcome |
 |
|
|
|
|
|
|
|