Zero2Cool
13 years ago
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.


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]
UserPostedImage
Zero2Cool
13 years ago
[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.
UserPostedImage
Zero2Cool
13 years ago
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.
UserPostedImage
Zero2Cool
13 years ago
[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.
UserPostedImage
Zero2Cool
13 years ago
+1
UserPostedImage
Fan Shout
Zero2Cool (2h) : I'm not sure I hope for that. I'll be at the game.
Martha Careful (16h) : I hope it is colder than a well-diggers ass on Thanksgiving night.
Zero2Cool (25-Nov) : doubt he wants to face the speedsters
beast (25-Nov) : Dolphins offense can be explosive... I wonder if we'll have Alexander back
Zero2Cool (25-Nov) : No Doubs could be issue Thursday
Mucky Tundra (25-Nov) : Bears. Santos. Blocked FG
Zero2Cool (24-Nov) : Bears. Vikings. OT
Mucky Tundra (24-Nov) : Thems the breaks I guess
Mucky Tundra (24-Nov) : Two players out and Williams had an injury designation this week but Oladapo is a healthy scratch
Zero2Cool (24-Nov) : Packers inactives vs 49ers: • CB Jaire Alexander • S Kitan Oladapo • LB Edgerrin Cooper • OL Jacob Monk
TheKanataThrilla (24-Nov) : Aaron Jones with a costly red zone fumble
Zero2Cool (24-Nov) : When we trade Malik for a 1st rounder, we'll need a new QB2.
packerfanoutwest (23-Nov) : Report: Aaron Rodgers wants to play in 2025, but not for the Jets
beast (23-Nov) : That's what I told the Police officer about my speed when he pulled me over
packerfanoutwest (23-Nov) : NFL told Bears that Packers’ blocked field goal was legal
packerfanoutwest (22-Nov) : 49ers are underdogs at Packers, ending streak of 36 straight games as favorites
Zero2Cool (22-Nov) : 49ers might be down their QB, DL, TE and LT?
packerfanoutwest (22-Nov) : Jaire Alexander says he has a torn PCL
Zero2Cool (20-Nov) : Even with the context it's ... what?
Mucky Tundra (20-Nov) : Matt LaFleur without context: “I don’t wanna pat you on the butt and you poop in my hand.”
beast (20-Nov) : We brought in a former Packers OL coach to help evaluate OL as a scout
beast (20-Nov) : Jets have been pretty good at picking DL
Zero2Cool (20-Nov) : He landed good players thanks to high draft slot. He isn't good.
Zero2Cool (20-Nov) : He can shove his knowledge up his ass. He knows nothing.
beast (20-Nov) : More knowledge, just like bring in the Jets head coach
Zero2Cool (19-Nov) : What? Why? Huh?
beast (19-Nov) : I wonder if the Packers might to try to bring Douglas in through Milt Hendrickson/Ravens connections
Zero2Cool (19-Nov) : The Jets fired Joe Douglas, per sources
packerfanoutwest (19-Nov) : Jets are a mess......
Zero2Cool (19-Nov) : Pretty sure Jets fired their scouting staff and just pluck former Packers.
Zero2Cool (19-Nov) : Jets sign Anders Carlson to their 53.
Zero2Cool (19-Nov) : When you cycle the weeks, the total over remains for season. But you get your W/L for that selected week. Confusing.
packerfanoutwest (19-Nov) : the total and percentage are the same as the previous weeks
packerfanoutwest (19-Nov) : the total and percentage are the same as the previous weeks
packerfanoutwest (19-Nov) : the totals are accurate..nrvrtmind
Zero2Cool (19-Nov) : I don't follow what you are saying. The totals are not the same as last week.
packerfanoutwest (19-Nov) : ok so then wht are the totals the same as last week?
Zero2Cool (19-Nov) : NFL Pick'em is auto updated when NFL Scores tab is clicked
Martha Careful (19-Nov) : The offense was OK. Let's not forget the Bear defense is very very good.
packerfanoutwest (19-Nov) : Who updates the leaderboard on NFLPickem?
beast (19-Nov) : Has the Packers offense been worse since the former Jets coach joined the Packers?
Zero2Cool (19-Nov) : Offense gets his ass in gear, this could be good.
Zero2Cool (19-Nov) : Backup QB helped with three wins. Special Teams contributed to three wins.
bboystyle (18-Nov) : Lions played outside thats why. They scored 16 and 17 in the only 2 outside games this year
Zero2Cool (18-Nov) : The rest of the NFL is catching up to Packers ... kicking is an issue throughout league
packerfanoutwest (18-Nov) : Packers DL Kenny Clark: We knew 'we were going to block' Bears' game-winning field goal attempt
Zero2Cool (18-Nov) : Lions seem to be throttling everyone, but only (only) got 24 lol maybe the rain is why
Zero2Cool (18-Nov) : Packers vs Lions game doesn't seem so bad.
beast (18-Nov) : Dennis Green "They are what we thought they were, and we let them off the hook!"
Martha Careful (17-Nov) : comment of the day Z2Cool "Bears better than we want to admit. Packers worse than we think. It's facts."
Please sign in to use Fan Shout
2024 Packers Schedule
Friday, Sep 6 @ 7:15 PM
Eagles
Sunday, Sep 15 @ 12:00 PM
COLTS
Sunday, Sep 22 @ 12:00 PM
Titans
Sunday, Sep 29 @ 12:00 PM
VIKINGS
Sunday, Oct 6 @ 3:25 PM
Rams
Sunday, Oct 13 @ 12:00 PM
CARDINALS
Sunday, Oct 20 @ 12:00 PM
TEXANS
Sunday, Oct 27 @ 12:00 PM
Jaguars
Sunday, Nov 3 @ 3:25 PM
LIONS
Sunday, Nov 17 @ 12:00 PM
Bears
Sunday, Nov 24 @ 3:25 PM
49ERS
Thursday, Nov 28 @ 7:20 PM
DOLPHINS
Thursday, Dec 5 @ 7:15 PM
Lions
Sunday, Dec 15 @ 7:20 PM
Seahawks
Monday, Dec 23 @ 7:15 PM
SAINTS
Sunday, Dec 29 @ 12:00 PM
Vikings
Saturday, Jan 4 @ 11:00 PM
BEARS
Recent Topics
1h / Green Bay Packers Talk / Zero2Cool

1h / Featured Content / Zero2Cool

15h / Green Bay Packers Talk / Zero2Cool

15h / Green Bay Packers Talk / bboystyle

22h / Green Bay Packers Talk / Zero2Cool

25-Nov / Green Bay Packers Talk / buckeyepackfan

24-Nov / Green Bay Packers Talk / buckeyepackfan

24-Nov / GameDay Threads / Zero2Cool

23-Nov / Green Bay Packers Talk / dfosterf

23-Nov / Green Bay Packers Talk / Zero2Cool

21-Nov / Green Bay Packers Talk / Martha Careful

21-Nov / Green Bay Packers Talk / Zero2Cool

21-Nov / Green Bay Packers Talk / beast

20-Nov / Green Bay Packers Talk / Zero2Cool

20-Nov / Green Bay Packers Talk / beast

Headlines
Copyright © 2006 - 2024 PackersHome.com™. All Rights Reserved.