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
buckeyepackfan (29-Apr) : Malachi Dupree wr LSU final pick.
buckeyepackfan (29-Apr) : 3rd rb Devante Mays Utah St
Zero2Cool (29-Apr) : from Albert Breer
Zero2Cool (29-Apr) : Through 99 picks, 17 corners and 11 safeties were picked. Crazy DB class.
Zero2Cool (28-Apr) : I've read there limited high end talent but a lot of good talent. I dunno. I'm not bummed though. Unless we take QB or K or P next lol
DarkaneRules (28-Apr) : well it's not deep at QB, hence why so many people are trading up for one
Zero2Cool (28-Apr) : We're gonna be trading back again. This is exciting! Great strategy if draft is as deep as we're being told.
DarkaneRules (28-Apr) : that moment will always be justin harrell for me
Pack93z (28-Apr) : I can honestly say, that might be the most disappointing moment under Ted Thompson, and impact edge player there, from Wisconsin, and they p
DarkaneRules (28-Apr) : hopefully they move back again. keep gettin' them picks
Smokey (28-Apr) : Nothing motivates a player like dropping from the 1st round and loosing 1st round money. GB's 1st second round pick will be ever so thrilled
Cheesey (28-Apr) : Dang..watched for 3 1/2 hours for THAT?!?
Smokey (27-Apr) : Zero your on the clock ; CHAT THE DRAFT ?
dhazer (27-Apr) : you mean a show that teams improve them selves and we wait all night for our pick and TT trades back lol
Zero2Cool (27-Apr) : NFL Draft is tonight, right?
Tezzy (27-Apr) : \_/ Smokey!
Smokey (26-Apr) : \_/ Tezzy
Tezzy (26-Apr) : I feel we are on the cusp of a special time of Packers football. My optimism for the rest of the 2000-teens is strong.
Tezzy (26-Apr) : Sign Cutler and draft a QB in round 1. Go Pack Go!!!!
TheKanataThrilla (25-Apr) : I will be there with beer in hand.
Smokey (25-Apr) : CHAT and Draft Thursday night in the PACKERSHOME CHAT ROOM ! Don't forget the cold beer .
TheKanataThrilla (21-Apr) : Seattle at Pack week 1. Hopefully Aaron gets some reps this preseason.
TheKanataThrilla (20-Apr) : Ruben Foster tests positive for weed. Any chance he falls to us? Probably not.
Smokey (20-Apr) : Thanks wpr, I'll order a L.Pizza !
wpr (20-Apr) : Smokey the chat room has been available for prior drafts
Smokey (20-Apr) : Great News , Zero . Also will the "Chat" room be up and operating for the 1st round of the NFL Draft ?
Zero2Cool (20-Apr) : Packers schedule coming out today, 7pm CST
Zero2Cool (19-Apr) : Fans should care about Dean Blandino’s departure from the NFL because it matters…a lot http://ble.ac/2osxh74
Zero2Cool (19-Apr) : Aaron Hernandez found dead in prison cell
Tezzy (18-Apr) : That stat line of 142 of 144 regular season games
Zero2Cool (18-Apr) : A.J. Hawk will retire with the @packers after recording the most tackles in franchise history (1,118)
Smokey (14-Apr) : Hernandez already convicted of previous two murders .
Smokey (14-Apr) : Aaron Hermandez found Not Guilty of Murder Charges .
Smokey (11-Apr) : Packers will play the Eagles , Redskins , Broncos , and Rams in Preseason 2017 .
Zero2Cool (11-Apr) : Odd to see GM John Lynch .. I won't get used to that for a while haha
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
Saturday, Dec 23 @ 7:30 PM
VIKINGS
Sunday, Dec 31 @ 12:00 PM
at Lions
Saturday, Dec 17 @ 12:00 PM
at Panthers
Think About It
Think About It
Recent Topics
2m / Green Bay Packers Talk / Smokey

1h / Green Bay Packers Talk / RaiderPride

2h / Green Bay Packers Talk / Bigbyfan

7h / Green Bay Packers Talk / nerdmann

7h / Green Bay Packers Talk / Smokey

8h / Green Bay Packers Talk / Laser Gunns

9h / Green Bay Packers Talk / yooperfan

10h / Green Bay Packers Talk / beast

12h / Green Bay Packers Talk / wpr

15h / Green Bay Packers Talk / coltonja

15h / Green Bay Packers Talk / DakotaT

15h / Green Bay Packers Talk / shield4life

16h / Green Bay Packers Talk / wpr

16h / Green Bay Packers Talk / wpr

16h / Green Bay Packers Talk / wpr

Headlines