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
gbguy20 (9h) : Martavis Bryant n whatnot
buckeyepackfan (24-Feb) : Smokey you can't lose something you never had.
buckeyepackfan (24-Feb) : Packers receive 4 comp picks for 2018. 4th, 2-5ths, 6th
Smokey (23-Feb) : Peters to the Rams
Smokey (23-Feb) : and another player is lost to another team. Deja Vu again !
Nonstopdrivel (22-Feb) : should have done*
Zero2Cool (21-Feb) : Hi 😊😉
TheKanataThrilla (21-Feb) : I guess I should have did a refresh when I walked away from the computer.
TheKanataThrilla (21-Feb) : Peters is 25 with one year left on his contract at just over $3M
Zero2Cool (21-Feb) : Mel Kiper sticks with Marcus Davenport to GB in 2nd mock
Zero2Cool (21-Feb) : As for Marcus Peters, how old is he an what's his contract years left?
Zero2Cool (21-Feb) : Packers got tired of Sitton's antics.
Zero2Cool (21-Feb) : Sitton was released not because of play or salary, but personality. He will not be re-signed.
TheKanataThrilla (21-Feb) : If we are planning on possibly cutting Cobb I can see the 2nd round pick. A second round pick for Peters is a pretty good deal.
Smokey (21-Feb) : I'd offer Cobb + a 3rd round pick + a 6th round pick in 2019 for the CB Peters from KC.
TheKanataThrilla (21-Feb) : I guess that is a highter round pick
TheKanataThrilla (21-Feb) : Suggestion was a 2nd round pick. I would want a lower round pick. I think that is too much. A 3rd or 4th seems about right.
Smokey (21-Feb) : Cobb and WHAT PICK ?
TheKanataThrilla (21-Feb) : A suggestion I saw was a trade of Cobb and a Pick for Peters. I think that would be a great move.
Smokey (21-Feb) : Sitton was drafted be GB in 2008, not a young man at this point, but still is a "bear" of a man.
Cheesey (21-Feb) : Sitton? Maybe if the price is right.
Cheesey (21-Feb) : I doubt the Packers would try to resign Sutton. But who knows? If the price is right?
Zero2Cool (20-Feb) : Bears declining option on Josh Sitton. He'll be Free Agent.
Zero2Cool (20-Feb) : Chiefs CB Marcus Peters trade rumors -- come to Packers!
Smokey (20-Feb) : Join us in Packershome and be part of the discussion today .
Zero2Cool (19-Feb) : Elizabeeth ... good bye
Zero2Cool (19-Feb) : Saturday, August 19, 2017
Zero2Cool (19-Feb) : That's dedicated spammng!
Nonstopdrivel (19-Feb) : For some reason, I had to flush my DNS cache to access this site from my laptop today.
Nonstopdrivel (19-Feb) : I prefer toads to frogs, Smokey, thank you very much.
Rockmolder (19-Feb) : My girlfriends says thanks, Rourke.
Smokey (19-Feb) : Nonstopdrivel that you most likely say to all the frogs you meet .
Nonstopdrivel (19-Feb) : Rockmolder's avatar is so fucking sexy.
gbguy20 (19-Feb) : never seen the interview before. tough to listen to. can't believe it was 7 years ago
gbguy20 (19-Feb) : just watched a nick Collins tribute on yourube. the end featured an interview with nick reflecting on his injury
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
2h / Green Bay Packers Talk / Cheesey

2h / Random Babble / Cheesey

6h / Green Bay Packers Talk / Smokey

7h / Green Bay Packers Talk / sschind

13h / Green Bay Packers Talk / wpr

15h / Green Bay Packers Talk / sschind

23-Feb / Fantasy Sports Talk / Smokey

23-Feb / Green Bay Packers Talk / Zero2Cool

23-Feb / Green Bay Packers Talk / Cheesey

23-Feb / Green Bay Packers Talk / Cheesey

23-Feb / Green Bay Packers Talk / nerdmann

22-Feb / Green Bay Packers Talk / Zero2Cool

22-Feb / Green Bay Packers Talk / Rockmolder

22-Feb / Green Bay Packers Talk / Cheesey

21-Feb / Random Babble / Smokey

Headlines