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 2005 Forums
 Transact-SQL (2005)
 Help with SubQuery

Author  Topic 

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2008-09-25 : 08:00:10
Hello,

What am I doing wrong here?


SELECT TOP (6) * FROM
Table_Topics_User ORDER BY lastVisit DESC
(select count(userid) from Table_Topics_Discussion where userid=61) as totalPosts


I want to get everything from Table_Topics_User and additionally get another column that has the count of rows where the criteria of that sub query is met.

I hope that makes sense.

Thank you.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 08:02:16
[code]SELECT TOP (6) *,
(select count(userid) from Table_Topics_Discussion where userid=61) as totalPosts
FROM
Table_Topics_User ORDER BY lastVisit DESC
[/code]
Go to Top of Page

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2008-09-25 : 08:47:21
As usual, your solution worked perfectly.

Visakh - you own this message board. I can't even count the number of times you've helped me these past couple months. The SQL community (not to mention me) are better off for having you around :)

Thanks again buddy!

-- shawn
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-25 : 08:54:41
quote:
Originally posted by shawnmolloy

As usual, your solution worked perfectly.

Visakh - you own this message board. I can't even count the number of times you've helped me these past couple months. The SQL community (not to mention me) are better off for having you around :)

Thanks again buddy!

-- shawn


welcome
Glad that i could help you out
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-25 : 09:12:29
quote:
Originally posted by shawnmolloy

As usual, your solution worked perfectly.

Visakh - you own this message board. I can't even count the number of times you've helped me these past couple months. The SQL community (not to mention me) are better off for having you around :)

Thanks again buddy!

-- shawn


This is the high credit for Visakh

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

shawnmolloy
Yak Posting Veteran

93 Posts

Posted - 2008-09-26 : 03:59:24
quote:
This is the high credit for Visakh


Yep... he deserves it; Visakh is my SQL hero. :D
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-09-26 : 04:00:25
quote:
Originally posted by shawnmolloy

quote:
This is the high credit for Visakh


Yep... he deserves it; Visakh is my SQL hero. :D


Thanks..
I'm honoured
Go to Top of Page
   

- Advertisement -