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 2000 Forums
 Transact-SQL (2000)
 Top with a Count

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_name

I 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_members
Order by member_name DESC

And I can grab a count by:

Select count(member_name) as M_HOWMANY
From site_members

But I can't seem to get the syntax correct when trying to combie these queries

Because 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_members
Order 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_name

I 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_members
Order by member_name DESC

And I can grab a count by:

Select count(member_name) as M_HOWMANY
From site_members

But I can't seem to get the syntax correct when trying to combie these queries

Because of the TOP 1 I keep getting the count as 1 which isn't correct.

Sorry if it's noobish question.

Go to Top of Page
   

- Advertisement -