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 |
|
becoop
Starting Member
2 Posts |
Posted - 2004-02-29 : 21:55:39
|
| I know this is probably an easy question, but I can seem to get the syntax to work. I have a table named site_members with a column named member_nameI want to select the top 1 record and in the same query grab a count of the total number of records using the member_name column.I can grab the top 1 by:Select TOP 1 member_name From site_membersOrder by member_name DESCAnd I can grab a count by:Select count(member_name) as M_HOWMANYFrom site_membersBut I can't seem to get the syntax correct when trying to combie these queriesBecause of the TOP 1 I keep getting the count as 1 which isn't correct. Sorry if it's noobish question. |
|
|
geossl
Yak Posting Veteran
85 Posts |
Posted - 2004-02-29 : 22:47:29
|
[code]Select TOP 1 member_name , (SELECT COUNT(*) FROM site_members)From site_membersOrder by member_name DESC[/code]quote: Originally posted by becoop I know this is probably an easy question, but I can seem to get the syntax to work. I have a table named site_members with a column named member_nameI want to select the top 1 record and in the same query grab a count of the total number of records using the member_name column.I can grab the top 1 by:Select TOP 1 member_name From site_membersOrder by member_name DESCAnd I can grab a count by:Select count(member_name) as M_HOWMANYFrom site_membersBut I can't seem to get the syntax correct when trying to combie these queriesBecause of the TOP 1 I keep getting the count as 1 which isn't correct. Sorry if it's noobish question.
|
 |
|
|
|
|
|