Discussion Board
Welcome Guest! You can login or register. Login or Register.

Options
Go to last post Go to first unread
Zero2Cool  
#1 Posted : Thursday, January 6, 2011 3:30:33 AM(UTC)
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]
Zero2Cool  
#2 Posted : Thursday, January 6, 2011 3:49:58 AM(UTC)
[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.
Zero2Cool  
#3 Posted : Thursday, January 6, 2011 4:34:42 AM(UTC)
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.
Zero2Cool  
#4 Posted : Thursday, January 6, 2011 4:47:16 AM(UTC)
[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.
Zero2Cool  
#5 Posted : Saturday, January 8, 2011 4:16:05 PM(UTC)
+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 (7h) : Ty Montgomery arrives at TC weighing a solid 222.8 lbs. !
Smokey (7h) : Tailgaters Fantasy Football is recruiting members, PM me for more info. .
Cheesey (25-Jul) : I like the white uni's. I'd like for them to wear the "chrome" helmets too! That would look neat!
Zero2Cool (24-Jul) : Color rush uniform game for the #Packers (all white) will be vs. #Bears Sept. 28, according to Mark Murphy
Zero2Cool (24-Jul) : "It's going to be a lot of fun for all our fans to drive across the state when we're in the Super Bowl in Minneapolis." Mark Murphy
Zero2Cool (24-Jul) : Mark Murphy: Super Bowl at Lambeau not possible
Smokey (24-Jul) : Training Camp for GB begins July 26th (Wednesday ) .
Smokey (22-Jul) : After 11 days with no Cable/Internet , I'm pleased to be back !
Porforis (21-Jul) : Misery + Money = Misery
Zero2Cool (21-Jul) : He left SIX kids fatherless. He had resources to get help, but sadly felt he was without hope.
Zero2Cool (21-Jul) : Has not*
Zero2Cool (21-Jul) : Money has and never will be a measure of happiness. Never.
Cheesey (21-Jul) : Another one kills himself. I don't get it. I guess money doesn't solve it all.
Zero2Cool (20-Jul) : Linkin Park Frontman Chester Bennington, 41, Dead
DarkaneRules (20-Jul) : RIP chester bennington :(
Zero2Cool (15-Jul) : Today's Birthdays: Since69 (52)
Cheesey (11-Jul) : Thanks Yoop! Smokey...I am "aged cheese!"LOL!
yooperfan (11-Jul) : Happy belated Birthday Cheesey
Smokey (10-Jul) : That's Gouda Cheesey ! LOL
Cheesey (10-Jul) : As Groucho Marx once said, "I'm gonna join a club, and beat you with it!"LOL!
Smokey (10-Jul) : Jolly Good Show , Welcome to the Club !
Cheesey (9-Jul) : Thanks guys. Officially a geezer now.
Zero2Cool (9-Jul) : Today's Birthdays: Cheesey (60) , DanJustDan29 (30)
wpr (9-Jul) : Happy birthday cheesey.
Zero2Cool (9-Jul) : Yo Alan!
Zero2Cool (9-Jul) : Today's Birthdays: Cheesey (60)
Smokey (5-Jul) : A good night to "You Tube" an old Football Game !
Smokey (5-Jul) : Lots of rain tonight across the nation !
Smokey (4-Jul) : Hello DoddPower
Smokey (3-Jul) : I recall the 200th as well, it was Spectacular !
Cheesey (3-Jul) : I remember the 200th....doesn't seem that long ago.
Smokey (3-Jul) : Happy 241st Birthday America !
Cheesey (3-Jul) : "Great taste, less filling!"LOL!
Smokey (3-Jul) : Mrs. Guion ? LOL
Cheesey (3-Jul) : I don't know...who hear wants to taste Guion???
Please sign in to use Fan Shout
2017 Packers Schedule
Sunday, Sep 10 @ 3:25 PM
SEAHAWKS
Sunday, Sep 17 @ 7:30 PM
at Falcons
Sunday, Sep 24 @ 3:25 PM
BENGALS
Thursday, Sep 28 @ 7:25 PM
BEARS
Sunday, Oct 8 @ 3:25 PM
at Cowboys
Sunday, Oct 15 @ 12:00 PM
at Vikings
Sunday, Oct 22 @ 12:00 PM
SAINTS
Sunday, Oct 29 @ 12:00 AM
- BYE -
Monday, Nov 6 @ 7:30 PM
LIONS
Sunday, Nov 12 @ 12:00 PM
at Bears
Sunday, Nov 19 @ 12:00 PM
RAVENS
Sunday, Nov 26 @ 7:30 PM
at Steelers
Sunday, Dec 3 @ 12:00 PM
BUCCANEERS
Sunday, Dec 10 @ 12:00 PM
at Browns
Sunday, Dec 17 @ 12:00 PM
at Panthers
Saturday, Dec 23 @ 7:30 PM
VIKINGS
Sunday, Dec 31 @ 12:00 PM
at Lions
Think About It
Think About It
Recent Topics
1h / Green Bay Packers Talk / Smokey

1h / Green Bay Packers Talk / Cheesey

6h / Around The NFL / Smokey

16h / Green Bay Packers Talk / wpr

17h / Green Bay Packers Talk / beast

17h / Green Bay Packers Talk / TheKanataThrilla

20h / Green Bay Packers Talk / beast

21h / Green Bay Packers Talk / pacmaniac

21h / Around The NFL / Cheesey

21h / Around The NFL / Cheesey

26-Jul / Green Bay Packers Talk / Smokey

24-Jul / Fantasy Sports Talk / Smokey

23-Jul / Green Bay Packers Talk / beast

23-Jul / Around The NFL / Smokey

21-Jul / Green Bay Packers Talk / Poppa San

Headlines