boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

select within a select

 
Post new topic   Reply to topic    boardom Forum Index -> PHP help
View previous topic :: View next topic  
Author Message
benny_01670



Joined: 11 Apr 2002
Posts: 22

PostPosted: Tue Jan 07, 2003 12:34 pm    Post subject: select within a select Reply with quote

I'm trying to use the following SQL query ... but cannot seem to get it to work.

Code:
SELECT id, title, post (SELECT count(Comment_id) FROM comments, blogs WHERE com_id = id) AS CommentCount FROM blogs DESC LIMIT 0, 7;


But it dosen't seem to work with the SELECT count in it.

Any ideas how I could use the above query correctly?

Thanks in advance
Ben
_________________
Ben Swinney
fcuk-me.net | do ya wanna?

ben at fcuk-me dot net
http://www.fcuk-me.net / http://www.fcuk-me.com
Back to top
View user's profile Send private message Visit poster's website
GamerZ



Joined: 15 May 2002
Posts: 536
Location: Singapore

PostPosted: Tue Jan 07, 2003 4:29 pm    Post subject: Reply with quote

Wait can i know what are you tryign to do? ur query is miexed? 2 from 2 select?
_________________

++ GamerZ.Per.Sg - Complex Simplicity
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
benny_01670



Joined: 11 Apr 2002
Posts: 22

PostPosted: Tue Jan 07, 2003 5:12 pm    Post subject: Reply with quote

I'm trying to select the number of comments replies to my blog.

This is the only way I can figure out how it may be done.

Hope this helps

Ben
_________________
Ben Swinney
fcuk-me.net | do ya wanna?

ben at fcuk-me dot net
http://www.fcuk-me.net / http://www.fcuk-me.com
Back to top
View user's profile Send private message Visit poster's website
cjc



Joined: 24 Dec 2002
Posts: 146
Location: New York

PostPosted: Tue Jan 07, 2003 6:32 pm    Post subject: Reply with quote

MySQL currently doesn't support subqueries (e.g., select within a select).
Back to top
View user's profile Send private message Visit poster's website
benny_01670



Joined: 11 Apr 2002
Posts: 22

PostPosted: Tue Jan 07, 2003 10:53 pm    Post subject: Reply with quote

Can you think of another method for obtaing the same results?

Ben
_________________
Ben Swinney
fcuk-me.net | do ya wanna?

ben at fcuk-me dot net
http://www.fcuk-me.net / http://www.fcuk-me.com
Back to top
View user's profile Send private message Visit poster's website
cjc



Joined: 24 Dec 2002
Posts: 146
Location: New York

PostPosted: Tue Jan 07, 2003 11:05 pm    Post subject: Reply with quote

Use temporary tables, or use PHP arrays to store the results of your COUNT.
Back to top
View user's profile Send private message Visit poster's website
mikelittle



Joined: 11 May 2002
Posts: 374
Location: UK

PostPosted: Tue Jan 07, 2003 11:42 pm    Post subject: Reply with quote

Benny,
do you want something like this?

Code:

SELECT ID, post_title, count(comment_ID) as comment_count
FROM b2posts LEFT JOIN b2comments ON ID = comment_post_id
GROUP BY ID
HAVING comment_count > 0
ORDER BY comment_count DESC LIMIT 7;


You may want to remove the having clause, if you wish to include posts without any comments.
Also I've sorted by number of comments I'm not sure that's what you wanted.


Hope this helps,
Mike
_________________
Mike Little
http://zed1.com/b2/
"Share what you know. Learn what you don't."
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> PHP help All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group