Green Bay Packers Forum

Welcome to your Green Bay Packers Online Community!

Since 2006, PackersHome has been providing a unique experience for fans.
Your participation is greatly anticipated!
Login or Register.
Options
Go to last post Go to first unread
Offline Zero2Cool  
#1 Posted : Thursday, January 6, 2011 3:30:33 AM(UTC)
Rank: Premier Member

Yahoo! NCAA March Madness - Gold: 2015Yahoo! Fantasy Football - Gold: 2009FleaFlicker Fantasy Football - Silver: 2010Yahoo! NCAA March Madness - Silver: 2011ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,346
Applause Received: 3,634
I'd like a SQL statement that finds the amount of posts for each user, then updates the specific field with that number.



On table_fpro_posts I want the count of posts that equal the poster_id and then update the field field_user_posts on table_users.

The relation between the tables would be user_id from the table_users table and poster_id from the table_fpro_posts table.


Code:
table_users		table_fpro_posts
user_id		=	poster_id



I've noticed several members with a post count that is not accurate and I'd like to fix that, but not sure where to start with the SQL command.


Getting the count isn't too hard, but I don't want to go through each member and manually update them. That's not fun.
[php]

SELECT COUNT(post_id)
FROM `cvs_fpro_posts`
WHERE poster_id = 2[/php]
Offline Zero2Cool  
#2 Posted : Thursday, January 6, 2011 3:49:58 AM(UTC)
Rank: Premier Member

Yahoo! NCAA March Madness - Gold: 2015Yahoo! Fantasy Football - Gold: 2009FleaFlicker Fantasy Football - Silver: 2010Yahoo! NCAA March Madness - Silver: 2011ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,346
Applause Received: 3,634
[php]UPDATE table_users
SET user_posts = COUNT(*)
FROM table_fpro_posts
WHERE table_fpro_posts.poster_id = table_users.user_id[/php]

That was my first guess, but I haven't ran it ... scared I'll break shit.
Offline Zero2Cool  
#3 Posted : Thursday, January 6, 2011 4:34:42 AM(UTC)
Rank: Premier Member

Yahoo! NCAA March Madness - Gold: 2015Yahoo! Fantasy Football - Gold: 2009FleaFlicker Fantasy Football - Silver: 2010Yahoo! NCAA March Madness - Silver: 2011ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,346
Applause Received: 3,634
Code:
SELECT table_fpro_posts.poster_id, count(table_fpro_posts.poster_id), table_users.user_id, table_users.user_posts
FROM table_users LEFT JOIN table_fpro_posts
ON table_users.user_id = table_fpro_posts.poster_id
GROUP BY table_fpro_posts.poster_id


This displays the members post count on their profile, next to the actual post count.
Offline Zero2Cool  
#4 Posted : Thursday, January 6, 2011 4:47:16 AM(UTC)
Rank: Premier Member

Yahoo! NCAA March Madness - Gold: 2015Yahoo! Fantasy Football - Gold: 2009FleaFlicker Fantasy Football - Silver: 2010Yahoo! NCAA March Madness - Silver: 2011ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,346
Applause Received: 3,634
[php]UPDATE table_users
SET table_users.user_posts = (SELECT COUNT(table_fpro_posts.poster_id)
FROM table_fpro_posts
WHERE table_users.user_id = table_fpro_posts.poster_id)[/php]

This did the trick.
Offline Zero2Cool  
#5 Posted : Saturday, January 8, 2011 4:16:05 PM(UTC)
Rank: Premier Member

Yahoo! NCAA March Madness - Gold: 2015Yahoo! Fantasy Football - Gold: 2009FleaFlicker Fantasy Football - Silver: 2010Yahoo! NCAA March Madness - Silver: 2011ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,346
Applause Received: 3,634
+1
Rss Feed 
Users browsing this topic
Guest
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Notification

Icon
Error


Fan Shout
Smokey (4h): NFL Football tonight on NBC !
uffda udfa (6h): Cancer sucks. Claims children and others way too young. Sorry, 4 your loss.
yinzer (13h): wpr, I'm sorry to hear of your loss
Cheesey (23-Aug): Wow, Wayne. Sorry to hear about that. It's never easy to lose a loved one, no matter what age.
Zero2Cool (22-Aug): Sorry, Wayne. :-(
wpr (22-Aug): Lost a friend to Pancreatic cancer. Bummed. He was only 55. Hard working dairy farmer. I am not sure if his kids will be up to the task.
Zero2Cool (21-Aug): Yes
LSUzilla (21-Aug): is there a prize for the pickem game this year?
Smokey (19-Aug): Mexican Mucky , your a genius ! Chimichangas !
Smokey (19-Aug): Sorry Zero, wilted lettuce does not qualify . LOL
Mucky Tundra (19-Aug): beef
Zero2Cool (19-Aug): ... me
Smokey (19-Aug): Meat of the day ? Chicken, Fish, or Pork ?
Smokey (15-Aug): Still Recruiting, The Tailgaters Fantasy Football League
Zero2Cool (15-Aug): Lions sign TE Andrew Quarless
Zero2Cool (15-Aug): I got sound working last night! Woohoo!
Smokey (13-Aug): Then , Maybe Not
buckeyepackfan (12-Aug): GAMEDAY NIGHT!!!!(sort of) GO! PACK! GO!
Zero2Cool (11-Aug): load it up billy!!
Smokey (10-Aug): Rugby reminds me of my childhood when the neighborhood lads all played "fumble ball" .
Smokey (10-Aug): I tune in for Olympic Archery and get half naked women playing in the sand ! Life is good !
Smokey (10-Aug): Still, The Shadow Knows .
Zero2Cool (10-Aug): You'll have to tune in Friday evening to find out. Dun dun dunnnnn!!!! ??
Smokey (10-Aug): Will the Browns game be in the Chat ?
gbguy20 (7-Aug): game cancelled.
Smokey (7-Aug): What's going on with the Chat , dhazer ?
gbguy20 (7-Aug): come onnnnnnnn
gbguy20 (7-Aug): why arent we streaming the speeches
Mucky Tundra (6-Aug): From Green Bay to New Orleans...two couldn't be further apart
Zero2Cool (6-Aug): Saints signing fullback John Kuhn
wpr (5-Aug): It rained in Illinois overnight
Smokey (5-Aug): Y U in Bangkok , fatguy ?
fatguy (5-Aug): Go Pack, Go
fatguy (5-Aug): Hello from Bangkok. It's raining.
Zero2Cool (2-Aug): Chargers will sign former Packers WR James Jones
Please sign in to use Fan Shout

Road To Super Bowl LI
Sunday, Sep 11 @ 12:00 PM
at Jaguars
Sunday, Sep 18 @ 7:30 PM
at Vikings
Sunday, Sep 25 @ 12:00 PM
LIONS
Sunday, Oct 2 @ 12:00 AM
BYE
Sunday, Oct 9 @ 7:30 PM
GIANTS
Sunday, Oct 16 @ 3:25 PM
COWBOYS
Thursday, Oct 20 @ 7:25 PM
BEARS
Sunday, Oct 30 @ 12:00 PM
at Falcons
Sunday, Nov 6 @ 3:25 PM
COLTS
Sunday, Nov 13 @ 12:00 PM
at Titans
Sunday, Nov 20 @ 7:30 PM
at Redskins
Monday, Nov 28 @ 7:30 PM
at Eagles
Sunday, Dec 4 @ 12:00 PM
TEXANS
Sunday, Dec 11 @ 3:25 PM
SEAHAWKS
Sunday, Dec 18 @ 12:00 PM
at Bears
Saturday, Dec 24 @ 12:00 PM
VIKINGS
Sunday, Jan 1 @ 12:00 PM
at Lions

Think About It
Think About It

Recent Topics
50m / Green Bay Packers Talk / Smokey

1h / Football Familiarity / Smokey

4h / Green Bay Packers Talk / uffda udfa

5h / Green Bay Packers Talk / uffda udfa

5h / Green Bay Packers Talk / sschind

6h / Around The NFL / Smokey

10h / Green Bay Packers Talk / gotarace

11h / Green Bay Packers Talk / Smokey

12h / Green Bay Packers Talk / PackerTraxx

24-Aug / Green Bay Packers Talk / Barfarn

24-Aug / Green Bay Packers Talk / uffda udfa

24-Aug / Green Bay Packers Talk / sschind

24-Aug / Packers Draft Threads / DarkaneRules

23-Aug / Green Bay Packers Talk / wpr

23-Aug / Green Bay Packers Talk / PackFanWithTwins


Packers Headlines