Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 16th, 2003, 04:28 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Recordset Problems...

I feel this should be easy, but I have been having a hell of a time with it.

I want to return a recordset (using T-SQL) that displays certain records in a table, with the last column displaying a count pulled from another table, using a key in its WHERE clause...

Something like:

SELECT
a.articleid,
a.title,
(select count(*) from blog_comments where ???)
FROM blog_articles a
INNER JOIN blog_comments c
ON a.articleid=c.articleid

...but where the third select parameter (select count(*) from blog_comments where ???)
returns the number of rows in the blog_comments table that match the articleid of the the each row in the blog_articles table.

So the resulting recordset would be something like:

10003 Fun with Books 6
10004 Fun with Kites 3
10005 Fun with Bikes 1

The 6,3, and 1 would be the number of rows in the blog_comments table with a matching articleid to 10003,1004, and 10005.

I have tried using cursors, but find that it returns multiple recordsets that aren't going to work in the upper layers of my app. And then there is the performance hit...

If I am not making any sense, please let me know...

Thanks, folks...

Ben


Reply With Quote
  #2 (permalink)  
Old October 16th, 2003, 04:45 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , Denmark.
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

If I understand you correctly, I think this will do it:

Code:
SELECT 
a.articleid,
a.title, 
(select count(*) from blog_comments c where c.articleid=a.articleid)
FROM blog_articles a
Reply With Quote
  #3 (permalink)  
Old October 16th, 2003, 05:22 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Holy over-complicating it, batman!

Thanks a lot, that did it...don't know what I was thinking there.

Ben

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recordset Problems toosuave PHP Databases 1 August 27th, 2006 09:03 PM
DAO Recordset Problems SteveH Access VBA 1 October 5th, 2005 05:39 PM
recordset problems p2ptolu Classic ASP Databases 0 July 9th, 2005 07:54 AM
Problems importing Excel into ADO.Net recordset AshleyC ADO.NET 0 February 22nd, 2005 05:56 AM
Recordset Problems Night_Zero Classic ASP Databases 17 July 15th, 2004 12:42 PM



All times are GMT -4. The time now is 10:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.