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,501
Applause Received: 4,045
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,501
Applause Received: 4,045
[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,501
Applause Received: 4,045
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,501
Applause Received: 4,045
[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,501
Applause Received: 4,045
+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
Porforis (6m) : What I'm more worried about at this point is WR injuries and Crosby being sick. Who'd be the backup if Crosby can't go?
Zero2Cool (10m) : We do have hope. Our secondary has improved. Also, he had to throw 80% to get 1 point up. That won't happen again.
Zero2Cool (13m) : I like to tease sometimes.
uffda udfa (32m) : Only 80%? :). We lost by one given that stat? Wish we had hope of tightening up.
uffda udfa (34m) : Z, u should tell everyone who Quintorris is. Quintorris Lopez Jones, better known as Julio.
Zero2Cool (35m) : Matt Ryan completed 80% of his passes against Packers in October.
uffda udfa (45m) : McGinn goes full on attack mode dismissing the notion of "Packers people". Harsh.
uffda udfa (46m) : McGinn says John Dorsey likely to be next Packers GM.
Zero2Cool (3h) : Boom! Davante Adams says last year's ankle injury "more difficult to deal with'
uffda udfa (6h) : Packers brass potentially leaving? Not worthy of discussing. Pressure Cooker? Never enough talk about them.
Zero2Cool (11h) : Put Quintorris in a pressure cooker.
uffda udfa (15h) : Back to football: Julio says he's going to play Sunday. Did NOT say he wouldn't be limited in the game.
uffda udfa (15h) : Anyone ever used their dishwasher to make their Thanksgiving turkey?
uffda udfa (15h) : Favorite Ronnie Milsap song? Smokey Mountain Rain or Any Day Now?
uffda udfa (19h) : Favorite GM candidate... Wolf or Gutekunst?
uffda udfa (19h) : I'd rather sit them than play them too compromised.
uffda udfa (19h) : Yeah, Z. More pressure cooker talk and smoked turkeys.
Zero2Cool (20h) : If this were a regular-season game, Nelson, Adams and Allison probably would not play, MM says.
Smokey (20h) : Mason Crosby is ill, hope it's not the Flu.
Smokey (21h) : Great, can we move past that story and get back to the Atlanta game ?
Zero2Cool (21h) : Packers exec Eliot Wolf has withdrawn his name for 49ers' GM job, as @TomPelissero reported. He didn't feel it was the right time.
TheKanataThrilla (22h) : We'll just have to score TDs then.
Zero2Cool (22h) : That's what we know.
Zero2Cool (22h) : Crosby, Mason K Illness
Smokey (22h) : Is He ill or not ?
Smokey (22h) : Raiderpride asked, "Anyone know what Crosby's illness is?"
Zero2Cool (22h) : Davante Adams expected to play- KFFL
Porforis (23h) : Alright, my opinion on Jordy has changed. If he's medically cleared to play, play him.
hardrocker950 (19-Jan) : By Sunday we won't have any WRs
Zero2Cool (19-Jan) : Geronimo hamstring, Janis quad. BEAUTIFUL.
Smokey (19-Jan) : Mason Crosby, is his health OK ?
Smokey (19-Jan) : Hello
FLORIDA PACKER88 (19-Jan) : Davis, G-Mo, and Janis will need to step up, but all three did score last time we played ATL!
FLORIDA PACKER88 (19-Jan) : Does Janis become a playoff hero second year in a row? Looks we're gonna have to find out either way regardless. Thank God for a healthy Cob
Smokey (19-Jan) : Is Mason Crosby's health OK ?
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
now / Green Bay Packers Talk / Porforis

8m / Green Bay Packers Talk / Porforis

12m / Green Bay Packers Talk / Porforis

13m / Green Bay Packers Talk / Zero2Cool

14m / Green Bay Packers Talk / DarkaneRules

41m / Green Bay Packers Talk / uffda udfa

1h / Green Bay Packers Talk / nerdmann

1h / Fantasy Sports Talk / SINCITYCHEEZE

3h / Green Bay Packers Talk / Zero2Cool

8h / Green Bay Packers Talk / Rick12

10h / Green Bay Packers Talk / Zero2Cool

11h / Green Bay Packers Talk / Zero2Cool

15h / Green Bay Packers Talk / uffda udfa

16h / Green Bay Packers Talk / The_Green_Ninja

16h / Green Bay Packers Talk / Dulak


Packers Headlines