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,448
Applause Received: 3,870
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,448
Applause Received: 3,870
[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,448
Applause Received: 3,870
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,448
Applause Received: 3,870
[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,448
Applause Received: 3,870
+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 (6h) : GO NAVY, BEAT ARMY !
Smokey (9-Dec) : 60% chance of SNOW in GB on Sunday. Most likely to fall before noon .
Smokey (8-Dec) : JOIN THE FORUM AND POST YOUR VIEWS !
The_Green_Ninja (8-Dec) : ...bro his senior year turns into a different person drunk. Gets in fights. And one time trashed out a Pita Pit by throwing his food
The_Green_Ninja (8-Dec) : Fun fact from people I know who knew Dak Prescott when he was at Mississippi State...
Pack93z (7-Dec) : @Dhazer Winning the regular season title.... lol... good for a soggy cookie... see you in the playoffs.. ;)
Nonstopdrivel (7-Dec) : In any case, Rashaan Salaam died this week.
Nonstopdrivel (7-Dec) : Didn't there used to be a member who posted as Rashaan Salami?
Smokey (7-Dec) : REMEMBER PEARL HARBOR , 75 years ago today. God Bless America
Zero2Cool (7-Dec) : Today's Birthdays: Gilligan (46)
Smokey (7-Dec) : The TFFL could use 4 more like you Jon. Know any that wants to join next year ?
Smokey (7-Dec) : I am proud of you Jon .
Smokey (7-Dec) : Yes Jon, you can indeed be proud of your efforts . I am .
rabidgopher04 (7-Dec) : league behind you and the other guy.
rabidgopher04 (7-Dec) : @Smokey - tough competition for sure. I'm not holding my breath. Just glad I could rebound after a bad start. 3rd most points scored in the
Smokey (7-Dec) : You won what other league dhazer ?
Smokey (7-Dec) : for
Smokey (7-Dec) : Low blow dhazer, 5 min. in the penalty box foe slashing ! lol
Smokey (7-Dec) : Yes, fine job rabid. Now compete with the other 9 - 4 in the league . ;) LOL !
rabidgopher04 (7-Dec) : Correction: I am second seed in the playoffs
rabidgopher04 (7-Dec) : I crawled my way back from 2-6 to 7-6 to win my division and 3rd place in Tailgaters FFL. Playoff should be fun.
Zero2Cool (6-Dec) : ;-)
dhazer (6-Dec) : i clinched last place in the Packershome thanks to the awesome draft skills of smokey lol and won the other league
Zero2Cool (6-Dec) : Wow. Rashaan Salaam was found dead Monday night at a park in Boulder. Police said there was no sign of foul play. He was 42
Pack93z (6-Dec) : In one league I went from 2-5 to 8-5 and clinched a playoff spot... #Believe Best I have for the Packers at the moment.
Zero2Cool (6-Dec) : Sweet. I backed my sweet ass into the playoffs. 8th and final seed.
Smokey (6-Dec) : Thank you Zero, I also just finished the Reg. Fantasy season at #1 . (Tailgaters Fantasy Football League ) .
The_Green_Ninja (5-Dec) : Same ol' Jay xD
Zero2Cool (5-Dec) : Aaron Rodgers over the last 7 games: 302 passing yards/game, 19 TDs, 3 INTs, 104.6 passer rating. 212 rushing yards, TD.
Zero2Cool (5-Dec) : Nice! I noticed you rocked your NFL Picks this week too! Nice work!!
Smokey (5-Dec) : Yes, he got me 29 fantasy points !
Zero2Cool (5-Dec) : Didn't David Johnson have a really good game though?
DarkaneRules (4-Dec) : cardinals run game looks worse than ours
Zero2Cool (4-Dec) : Packers inactives v Texans: WR Trevor Davis CB Makinton Dorleant ILB Blake Martinez OLB Kyler Fackrell RG Lang C Tretter DT Christian Ringo
buckeyepackfan (4-Dec) : GOOD MORNING PACKER FANS! GAMEDAY! GO! PACK! GO!
Please sign in to use Fan Shout

2016 Packers Schedule
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 @ 3:25 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
1h / Green Bay Packers Talk / nerdmann

19h / Green Bay Packers Talk / nerdmann

19h / Green Bay Packers Talk / nerdmann

9-Dec / Green Bay Packers Talk / The_Green_Ninja

9-Dec / Fantasy Sports Talk / Smokey

8-Dec / Green Bay Packers Talk / Zero2Cool

8-Dec / Green Bay Packers Talk / Zero2Cool

8-Dec / Green Bay Packers Talk / steveishere

7-Dec / Green Bay Packers Talk / Porforis

7-Dec / Green Bay Packers Talk / Zero2Cool

7-Dec / Green Bay Packers Talk / PackFanWithTwins

7-Dec / Green Bay Packers Talk / Zero2Cool

7-Dec / Green Bay Packers Talk / Zero2Cool

6-Dec / Fantasy Sports Talk / Zero2Cool

6-Dec / Green Bay Packers Talk / packerfanoutwest


Packers Headlines