Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2013, 12:07 AM   PM User | #1
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
Most active query

Hello. I have a problem and i cant find solution i have this query:

Code:
SELECT st.id,st.typ_statusu,st.blog_nadpis_slug,st.nick,st.status,st.youtube,st.shared_from_id,st.image_big,st.time,tu.profile_picture_statuses as profilovka,
sl.status_id as idecko,COUNT(sl.id) AS magnitude
FROM status_likes as sl

INNER JOIN statuses as st
ON sl.status_id=st.id

INNER JOIN users As tu
ON st.nick=tu.nick

WHERE st.time>1355005482

GROUP BY sl.status_id
ORDER BY magnitude DESC
                                           LIMIT 50
Little be slow but works good... In this query i select statuses in certain time to past ...and then to each status i am counting the number of likes. To end of query i select just some info(picture) from another query as you can see.

But my problem is:

I need to remake the query to not only count likes... but also count comments from another table! And then order them.

I absolutly lost...

I tried something like this but this is junk:

Code:
SELECT st.id,st.typ_statusu,st.blog_nadpis_slug,st.nick,st.status,st.youtube,st.shared_from_id,st.image_big,st.time,tu.profile_picture_statuses as profilovka,
sl.status_id as idecko,COUNT(sl.id) AS magnitude, COUNT(co.id) AS magnitude2
FROM status_likes as sl

INNER JOIN statuses as st
ON sl.status_id=st.id

INNER JOIN users As tu
ON st.nick=tu.nick

INNER JOIN comments as co
ON co.status_id=st.id

WHERE st.time>1355005482

GROUP BY sl.status_id
ORDER BY magnitude DESC
                                           LIMIT 50
Photo of tables i think i dont have to upload because from code is clear:
likes: collum with status_id(which is ID of status from status table...)
comments: the same system.

IF SOMEONE COULD HELP I WOULD BE REALLY GLAD! :/

Last edited by Trki; 01-24-2013 at 08:32 PM..
Trki is offline   Reply With Quote
Old 01-24-2013, 10:06 AM   PM User | #2
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
So noone know how to do it? :/ :P
Trki is offline   Reply With Quote
Old 01-24-2013, 03:25 PM   PM User | #3
jerry62704
Senior Coder

 
jerry62704's Avatar
 
Join Date: Oct 2007
Location: Springfield, IL
Posts: 1,046
Thanks: 9
Thanked 81 Times in 81 Posts
jerry62704 is on a distinguished road
Have you tried a subquery on the new counter field?
__________________
.
.
...and gladly would he learn and gladly teach

Visit www.LiberalsWin.com for humor and the unique Bush/Obama Approval Polls
jerry62704 is offline   Reply With Quote
Old 01-24-2013, 05:55 PM   PM User | #4
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
Quote:
Originally Posted by jerry62704 View Post
Have you tried a subquery on the new counter field?
No dont know how you think it. Could u please try it? I still try to get result but i cant and cant

But maybe there is another way... what i need is to select statuses from 24h back to example. And i need to order them by MOST ACTIVE (so sum the top liked and top commented ) and order :/

Last edited by Trki; 01-24-2013 at 06:01 PM..
Trki is offline   Reply With Quote
Old 01-24-2013, 08:27 PM   PM User | #5
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
try to change
COUNT(co.id)
to
COUNT(distinct co.id)

In your second query, that might make it do a thing, doh I don't guarantie nothing.
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search
BubikolRamios is offline   Reply With Quote
Old 01-24-2013, 08:31 PM   PM User | #6
BubikolRamios
Senior Coder

 
Join Date: Dec 2005
Location: Slovenia
Posts: 1,876
Thanks: 114
Thanked 76 Times in 76 Posts
BubikolRamios is on a distinguished road
Note allso: INNER is useless, exact same thing will be in result if you don't use it at all.

Doesnt look like you are familiare with LEFT JOIN.

Note that that would show you allso records where there is no comments at all.
__________________
Found a flower or bug and don't know what it is ?
agrozoo.net galery
if you don't spot search button at once, there is search form:
agrozoo.net galery search
BubikolRamios is offline   Reply With Quote
Old 01-24-2013, 08:31 PM   PM User | #7
Trki
Regular Coder

 
Join Date: Jan 2012
Location: Slovakia
Posts: 106
Thanks: 9
Thanked 0 Times in 0 Posts
Trki is an unknown quantity at this point
Quote:
Originally Posted by BubikolRamios View Post
try to change
COUNT(co.id)
to
COUNT(distinct co.id)

In your second query, that might make it do a thing, doh I don't guarantie nothing.
no it will not help :P And btw: i finallllllyyyyyy afffteeer three days have DONE IT!! ah i am so happy :P My friend helped me out. The problem was ... ehm it was all wrong
Trki is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:47 PM.


Advertisement
Log in to turn off these ads.