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 (10h) : not so , Miami voted no .
Nonstopdrivel (10h) : The twist? The only team to vote against the move was Oakland.
Smokey (12h) : NFL Owner's vote 31 - 1 for the Raiders to move to Las Vegas in 2020 .
Zero2Cool (18h) : Mark Murphy: Teams paid 'more than we thought was reasonable' for Packers' free agents
Zero2Cool (19h) : Seahawks backup quarterback arrested for marijuana possession after car he was riding in drives into a bar
Zero2Cool (19h) : I see JT, you should tell JT to post.
hardrocker950 (27-Mar) : Nice to see that Dorleant got arrested just a few miles from here...
Cheesey (26-Mar) : Sanchez with the Bears....LOLOLOL!!!!
Zero2Cool (26-Mar) : We should hope it does not happen.
hardrocker950 (25-Mar) : I doubt that happens...
Smokey (24-Mar) : GB needs to trade up in the draft to get THE Ohio State CB - Marshon Lattimore !
Zero2Cool (24-Mar) : QB Mark Sanchez joining the Bears.
Zero2Cool (24-Mar) : double it up
Zero2Cool (24-Mar) : I'm kidding, relax....
Zero2Cool (24-Mar) : and now he has been cut
uffda udfa (23-Mar) : Per Schefter: Former Skins DT Ricky Jean Francois signed a one-year, $3M deal with Packers, per source.
uffda udfa (23-Mar) : Per Schefter: FormerSkins DT Ricky Jean Francois signed a one-year, $3M deal with Packers, per source.
Zero2Cool (23-Mar) : lol by .01 not what i thought
Zero2Cool (23-Mar) : he's faster than Montgomery
uffda udfa (22-Mar) : Packers re-sign Christine Michael
Smokey (22-Mar) : Easier said than fixed .
Nonstopdrivel (22-Mar) : The web version lists who started the thread; the mobile version lists who last updated it.
Nonstopdrivel (22-Mar) : Also, there's a weird disparity between the web version and online version of this site.
Nonstopdrivel (22-Mar) : ;-)
Zero2Cool (21-Mar) : Packers wanted D. Ware in 2005. Thank you Cowboys!
Zero2Cool (21-Mar) : lol Rourke
Nonstopdrivel (21-Mar) : I HATE HATE HATE the way all threads get marked as read after viewing a few of them in one session. It's obnoxious.
Smokey (21-Mar) : Check out this site, NFLdraftscout.com , a great resource site.
Smokey (20-Mar) : Jared Cook signs with Raiders .
Smokey (20-Mar) : I did watch SB 45 on YouTube the other night, very eye opening .
Smokey (20-Mar) : Watching Spring Training Baseball, Nationals vs Yankees, very interesting .
Zero2Cool (19-Mar) : B1G making some noise in that bracket
Zero2Cool (19-Mar) : The more join, the more talk, the better. including John
Zero2Cool (19-Mar) : no forum should need one person, we have others, speak up!
gbguy20 (19-Mar) : slow forum needs more uffda
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
1h / Green Bay Packers Talk / Smokey

4h / Green Bay Packers Talk / beast

8h / Green Bay Packers Talk / wpr

8h / Green Bay Packers Talk / wpr

8h / Fantasy Sports Talk / Smokey

11h / Green Bay Packers Talk / DoddPower

18h / Green Bay Packers Talk / RainX

19h / Around The NFL / Zero2Cool

26-Mar / Green Bay Packers Talk / Zero2Cool

26-Mar / Green Bay Packers Talk / beast

25-Mar / Green Bay Packers Talk / buckeyepackfan

23-Mar / Green Bay Packers Talk / PackFanWithTwins

23-Mar / Green Bay Packers Talk / nerdmann

23-Mar / Announcements / Zero2Cool

23-Mar / Green Bay Packers Talk / Zero2Cool

Headlines