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: 2011FleaFlicker Fantasy Football - Bronze: 2016ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,496
Applause Received: 4,032
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: 2011FleaFlicker Fantasy Football - Bronze: 2016ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,496
Applause Received: 4,032
[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: 2011FleaFlicker Fantasy Football - Bronze: 2016ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,496
Applause Received: 4,032
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: 2011FleaFlicker Fantasy Football - Bronze: 2016ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,496
Applause Received: 4,032
[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: 2011FleaFlicker Fantasy Football - Bronze: 2016ESPN NCAA March Madness - Bronze: 2010Yahoo! NCAA March Madness - Bronze: 2013

United States
Joined: 10/13/2006(UTC)
Location: Green Bay, WI
Applause Given: 2,496
Applause Received: 4,032
+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
Zero2Cool (2h) : from Rob Reischel @robreischel
Zero2Cool (2h) : Rodgers has played in 2 NFC Championship games. QB ratings were 56.7 and 55.9. That's won't cut it Sunday
Porforis (3h) : Have to fill the 24/7 news cycle with something.
Smokey (3h) : True, Zero
Zero2Cool (3h) : Rodgers didn't draw it up, it was selected from options. Duh.
uffda udfa (5h) : Zeke Elliott tired of domestic violence investigation. NFL moving forward now.
Smokey (11h) : Did u fire up the crock pot ?
Smokey (11h) : Jolly good show ole chap ! LOL
Cheesey (11h) : Smokey! Darn spell check! LOL!
Cheesey (11h) : Hey smiley! Just saw your shout out! How bout them Packers!
Smokey (11h) : Hello Cheesey !
GoPack1984 (14h) : I hope not. Please be something like 41-28 Packers.
uffda udfa (14h) : I agree with Chmura. This looks like a double 40 burger.
uffda udfa (14h) : The hug on the sidelines?
uffda udfa (14h) : What seemed so emotional?
Zero2Cool (14h) : No, but I am curious why that seemed so emotional. I might be reading into it too much.
uffda udfa (15h) : Anyone ever get confused looking at Alex Van Pelt thinking it's MM?
uffda udfa (16h) : I hope they aren't going to dial it down believing in destiny .
Zero2Cool (17h) : Jason Wilde: Packers "feel like a team of destiny"
uffda udfa (19h) : They'll need all the Julio Joneses they can get.
Zero2Cool (19h) : Chmura: "I'll tell you this: Atlanta's going to score 40 points. They are. The #Packers are going to have to score 41."
Zero2Cool (16-Jan) : Damn-Falcons coach Dan Quinn tells reporters that WR Julio Jones (foot) will be limited this week but will be “ready to rock” on Sunday.
Zero2Cool (16-Jan) : Packers defense has a red zone INT in each of the last 3 games... Hyde with two of them. (One being the clutch 4thQ INT vs DET in Week 17)
Zero2Cool (16-Jan) : Randall Cobb, Damarious Randall, Quentin Rollins, James Starks, Clay Matthews, Ty Montgomery & Jared Cook. OUT
Zero2Cool (16-Jan) : Packers inactive list when they lost 33-32 to the Falcons week 8.
Zero2Cool (16-Jan) : There is no emphasis, it's just a little bit of info. Take it or leave it. No harm.
Smokey (16-Jan) : Zero, I believe that you and some others place too much emphasis upon data. no harm intended.
Zero2Cool (16-Jan) : It’s the 1st time since 1970 all 4 conference championship teams finished the regular season on winning streaks of 4+ games
TheKanataThrilla (16-Jan) : Salt mine. Love it.
TheKanataThrilla (16-Jan) : The refs kept that game close. We should have blown them out early.
DarkaneRules (16-Jan) : Hyde and Gunter are special and I'm hopeful D Ran gets back to where he can be
mi_keys (16-Jan) : That whole forum is a salt mine. It's beautiful.
Zero2Cool (16-Jan) : Burnett's back up, Kentrell Brice lead team in tackles.
uffda udfa (16-Jan) : Hilarious reading below. I like Carter. Only guy who gets it.
uffda udfa (16-Jan) : http://boards.dallascowboys.com/topic/71647-so-we-are-supposed-to-believe/#entry3978081
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 @ 7:30 PM
at Lions

Think About It
Think About It

Recent Topics
3m / Green Bay Packers Talk / PackFanWithTwins

26m / Green Bay Packers Talk / wpr

2h / Green Bay Packers Talk / wpr

2h / Green Bay Packers Talk / wpr

2h / Green Bay Packers Talk / musccy

3h / Green Bay Packers Talk / Smokey

4h / Green Bay Packers Talk / wpr

4h / Green Bay Packers Talk / wpr

14h / Green Bay Packers Talk / PackFanWithTwins

14h / Fantasy Sports Talk / rabidgopher04

15h / Green Bay Packers Talk / uffda udfa

16h / Green Bay Packers Talk / Rick12

17h / Green Bay Packers Talk / Rick12

19h / Green Bay Packers Talk / uffda udfa

19h / Green Bay Packers Talk / PackFanWithTwins


Packers Headlines