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 (20h) : 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???
Zero2Cool (1-Jul) : Today's Birthdays: Grabacr (29)
Smokey (30-Jun) : Guion did wrong , but he may also have good taste .
Porforis (30-Jun) : Guion probably went out to get something better than meatloaf.
Smokey (30-Jun) : So would you like a metal or a chest to hang it on ?
Zero2Cool (30-Jun) : Stupid emoji. It's not two question marks. It's a winky face!! Guess I need to run this house gooder lol
Zero2Cool (30-Jun) : And I run this house. Understand that. ??
Zero2Cool (30-Jun) : Bahahahhaha basement
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
43m / Green Bay Packers Talk / Smokey

2h / Green Bay Packers Talk / buckeyepackfan

2h / Around The NFL / Smokey

21-Jul / Green Bay Packers Talk / Poppa San

21-Jul / Green Bay Packers Talk / beast

21-Jul / Green Bay Packers Talk / Poppa San

21-Jul / Green Bay Packers Talk / Poppa San

21-Jul / Around The NFL / Poppa San

21-Jul / Around The NFL / Poppa San

19-Jul / Green Bay Packers Talk / dhazer

19-Jul / Green Bay Packers Talk / steveishere

19-Jul / Green Bay Packers Talk / isocleas2

19-Jul / Green Bay Packers Talk / DoddPower

18-Jul / Green Bay Packers Talk / Cheesey

16-Jul / Green Bay Packers Talk / beast

Headlines