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
dhazer (1h) : you mean a show that teams improve them selves and we wait all night for our pick and TT trades back lol
Zero2Cool (4h) : NFL Draft is tonight, right?
Tezzy (22h) : \_/ 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
Cheesey (10-Apr) : I don't think she has anything to do with how he plays on the field.
Porforis (7-Apr) : 100% conjecture but maybe they've been on the rocks and that contributed to his long slump?
Zero2Cool (7-Apr) : Aaron Rodgers and actress Olivia Munn break up, People magazine reports. Here we go
Porforis (7-Apr) : Forum needs some FOOTBAH! l.
gbguy20 (6-Apr) : forum needs some uffda
Zero2Cool (5-Apr) : Marshawn Lynch told the @RAIDERS he intends to un-retire.
iscmarkiemark (5-Apr) : Garrett could be gone in the 1st even..
Smokey (2-Apr) : A REMINDER: Easter Sunday falls on April 16th .
Smokey (1-Apr) : Avoid the Rush, join today !
Zero2Cool (31-Mar) : 8 of 12 top draft picks from 2013 - are no longer with the team that drafted them...
FLORIDA PACKER88 (31-Mar) : I don't think Myles Garrett will be there in the 3rd haha
Nonstopdrivel (30-Mar) : NFL Network predicting Packers to trade out of 2nd round to snag Myles Garrett (DE, Texas A&M) in the 3rd round.
Smokey (30-Mar) : Packers sign OG Justin McCray, 321 lbs out of C.Florida .
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
1h / Green Bay Packers Talk / Cheesey

2h / Green Bay Packers Talk / beast

18h / Green Bay Packers Talk / nerdmann

23h / Green Bay Packers Talk / wpr

23h / Green Bay Packers Talk / wpr

26-Apr / Green Bay Packers Talk / Tezzy

26-Apr / Green Bay Packers Talk / Tezzy

25-Apr / Green Bay Packers Talk / PackFanWithTwins

24-Apr / Green Bay Packers Talk / PackFanWithTwins

24-Apr / Green Bay Packers Talk / PackFanWithTwins

22-Apr / Green Bay Packers Talk / Zero2Cool

21-Apr / Green Bay Packers Talk / FLORIDA PACKER88

20-Apr / Around The NFL / Smokey

19-Apr / Green Bay Packers Talk / wpr

19-Apr / Green Bay Packers Talk / sschind

Headlines