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
uffda udfa (7h) : Canes lose 24-14 to previously 4-7 Pitt. Play Clemson in Conf. Championship next.
uffda udfa (8h) : *Miami
uffda udfa (8h) : .iai trails Pitt by 10 with under 2 minutes in 3rd qtr.
uffda udfa (9h) : Pitt up in 3rd qtr... 2nd week in a row Miami has struggled. Badgers could jump.
uffda udfa (9h) : The Canes belong on a Christmas tree not in a football playoff.
TheKanataThrilla (9h) : I might feel glad I am going to miss most of our Packer game.
wpr (11h) : That's awesome Thrilla. Have a great time
TheKanataThrilla (12h) : Got myself some tickets to the Grey Cup this Sunday. Taking my son.
TheKanataThrilla (24-Nov) : Cousins is pretty good. Thankfully coaches were willing to lack past early draft rounds to play him.
wpr (24-Nov) : Merry Thanksgiving to all. ;)
Zero2Cool (24-Nov) : uffda udfa -- if you want your name changed, send me a Private Message with new name
yinzer (24-Nov) : probably not, eh?
Zero2Cool (24-Nov) : Wonder if Chargers fans say regime is wasting Rivers.
yinzer (24-Nov) : old school
TheKanataThrilla (24-Nov) : Fave non-GB players. Love QBs so going Brees and Rivers.
hardrocker950 (24-Nov) : Hayward with a pick
TheKanataThrilla (23-Nov) : Love Rivers. Wish he'd find a great team to play for.
nerdmann (23-Nov) : Shit could turn around for us.
nerdmann (23-Nov) : Loins lost and the 'Gurlz are losing (not to jinx)
yinzer (23-Nov) : Ya got my vote on the name change, uffda udfa haha
TheKanataThrilla (23-Nov) : The claim is highly sweaty balls..
uffda udfa (23-Nov) : Wait... Pee Stain 76...would be better.
uffda udfa (23-Nov) : Checked settings and couldn't get it done.
uffda udfa (23-Nov) : Can I change my screen name from uffda to: Mike Daniels' Pee Stain ?
TheKanataThrilla (23-Nov) : I hate the endzone rule, Detroit got hosed on that call.
uffda udfa (23-Nov) : Happy Thanksgiving you homers! Ha ha.
TheKanataThrilla (23-Nov) : Yoop I am up from New York. Ogdenbugh is about an hour drive. Close to Syracuse as well, but never checked out any football or basketball ga
Zero2Cool (23-Nov) : Today's Birthdays: polargrizz (63)
TheKanataThrilla (23-Nov) : Go Lions, Chargers and Redskins. No doubt they all will lose as I am terrible on picking the Thursday game.
TheKanataThrilla (23-Nov) : My football pool buddies and I will be celebrating. We even have a bar that'll serve a turkey dinner.
TheKanataThrilla (23-Nov) : Hahahaha
yooperfan (23-Nov) : Happy Thanksgiving to all Packers fans from da U.P.of Michigan eh ??
TheKanataThrilla (23-Nov) : Happy Thanks Giving to my friends in the South. We should all be thankful for Aaron Rodgers for obvious reasons. Go Pack Go!!!
Nonstopdrivel (23-Nov) : Happy Thanksgiving to you too.
buckeyepackfan (23-Nov) : HAPPY THANKSGIVING PACKER FANS!!
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
5m / Green Bay Packers Talk / packerfanoutwest

1h / Green Bay Packers Talk / TheKanataThrilla

2h / Green Bay Packers Talk / nerdmann

5h / Green Bay Packers Talk / Cheesey

5h / Green Bay Packers Talk / Cheesey

7h / Green Bay Packers Talk / sschind

9h / Green Bay Packers Talk / uffda udfa

10h / Green Bay Packers Talk / uffda udfa

23-Nov / Green Bay Packers Talk / dhazer

23-Nov / Green Bay Packers Talk / DoddPower

23-Nov / Green Bay Packers Talk / Cheesey

23-Nov / Green Bay Packers Talk / uffda udfa

22-Nov / Green Bay Packers Talk / buckeyepackfan

22-Nov / Green Bay Packers Talk / Zero2Cool

22-Nov / Green Bay Packers Talk / buckeyepackfan

Headlines