quick question on left join query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

quick question on left join query

Post by scarface222 »

"SELECT scrusersonline.*, COUNT(scrusersonline.usersonlineid) AS idcount FROM scrusersonline LEFT JOIN topic ON topic.topic_id=scrusersonline.topic_id WHERE topic.subject_id='$type' scrusersonline.usersonlineusrip!='1' AND scrusersonline.id!='0' GROUP BY scrusersonline.topic_id ORDER BY scrusersonline.idcount DESC"

Anyone know why this does not work? without the join it works fine, and I have joined other queries without a problem, the only difference is that I need a count number in this one. If anyone can help me out or give me a tip, I would really appreciate it.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: quick question on left join query

Post by califdon »

scarface222 wrote:"SELECT scrusersonline.*, COUNT(scrusersonline.usersonlineid) AS idcount FROM scrusersonline LEFT JOIN topic ON topic.topic_id=scrusersonline.topic_id WHERE topic.subject_id='$type' scrusersonline.usersonlineusrip!='1' AND scrusersonline.id!='0' GROUP BY scrusersonline.topic_id ORDER BY scrusersonline.idcount DESC"

Anyone know why this does not work? without the join it works fine, and I have joined other queries without a problem, the only difference is that I need a count number in this one. If anyone can help me out or give me a tip, I would really appreciate it.
You're telling it to ORDER BY a field of the table scrusersonline that's named idcount, but there is no such field. Just remove the red part.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: quick question on left join query

Post by mikosiko »

"SELECT scrusersonline.*, COUNT(scrusersonline.usersonlineid) AS idcount FROM scrusersonline LEFT JOIN topic ON topic.topic_id=scrusersonline.topic_id WHERE topic.subject_id='$type' scrusersonline.usersonlineusrip!='1' AND scrusersonline.id!='0' GROUP BY scrusersonline.topic_id ORDER BY scrusersonline.idcount DESC"
and in addition to that...also maybe because here (in red) something is missing

WHERE topic.subject_id='$type' scrusersonline.usersonlineusrip!='1' AND scrusersonline.id!='0'
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: quick question on left join query

Post by califdon »

Good catch, mikosiko. I overlooked that omission.
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: quick question on left join query

Post by scarface222 »

lmao I love you guys. I will try to be much more vigilante.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: quick question on left join query

Post by Eran »

I think you meant vigilant...
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: quick question on left join query

Post by mikosiko »

pytrin wrote:I think you meant vigilant...
are you trying to win the "BEST SPELL CHECKER" bumper sticker ? :wink:

bumper sticker = that little thing in your signature :)
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: quick question on left join query

Post by Eran »

this is not a misspelling, vigilante is a different word..
scarface222
Forum Contributor
Posts: 354
Joined: Thu Mar 26, 2009 8:16 pm

Re: quick question on left join query

Post by scarface222 »

hahahaha pytrin you help me with my code and my grammar, you're my boy on this forum.

vigilant keenly watchful to detect danger; wary: a vigilant sentry.

vigilante any person who takes the law into his or her own hands, as by avenging a crime.

however, I did actually mean to kill criminals and to wrongfully apply the word as an adjective, so you're wrong...
Last edited by scarface222 on Sat Feb 27, 2010 6:42 pm, edited 1 time in total.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: quick question on left join query

Post by mikosiko »

pytrin wrote:this is not a misspelling, vigilante is a different word..
no matter.... the joke was good anyways ... c'mon... smile :D
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: quick question on left join query

Post by Eran »

however, I did actually mean to kill criminals and to wrongfully apply the word as an adjective, so your wrong...
now, that would be amusing ;)
Post Reply