MySQL: Update all values in table from another table
#1

Hi.

I want to run this result for all players in the table, but I don't know how to do it.

Here's the result, this works, but I only can run it for one row and this is doesn't works with multipie rows.

UPDATE players SET maths = (SELECT COUNT( winner_id) FROM maths)

This will update all data for same value in players table, and this is the problem.
Reply
#2

sorry i dont understand what you mean
Reply
#3

Shit, sorry for my bad english.

I want to update the "maths" in `players` table for number of rows for the player reg id from math table, but this will count all reg id in maths table and will update the players table for same value.

Example:

Code:
for(new i; i < MaxPlayerIDInPlayersTable; i++)
{
"UPDATE players SET maths = (SELECT COUNT( winner_id) FROM maths WHERE winner_id = i) WHERE id = i"
}
If there will no idea, i will run similar query with mysql plugin from samp server.. This is not the best idea, but I don't know another result now
Reply
#4

Now I understand i think....

first tell me which plugin you use
Reply
#5

Quote:
Originally Posted by Mellnik
View Post
Now I understand i think....

first tell me which plugin you use
BlueG's R7 plugin, but after some calculations run this query in cicle in samp server is impossible, because i have ~90k players..
Reply
#6

Quote:
Originally Posted by kurta999
View Post
BlueG's R7 plugin, but after some calculations run this query in cicle in samp server is impossible, because i have ~90k players..
LOL
Quote:

I want to update the "maths" in `players` table for number of rows for the player reg id from math table, but this will count all reg id in maths table and will update the players table for same value.

Did i understand that:

1. you want to get the count of all rows in table "math"
2 then you wan to insert received number into "maths" from the table players
?
Reply
#7

UPDATE players SET maths=(SELECT COUNT(winner_id) FROM maths WHERE maths.winner_id=players.id)
What about this one?
Reply
#8

Quote:
Originally Posted by AndreT
View Post
UPDATE players SET maths=(SELECT COUNT(winner_id) FROM maths WHERE maths.winner_id=players.id)
What about this one?
I'm idiot.. LoL
Thanks!

Very nice, this works!

I now searched for while loop in mysql, and other shits, but this solved my problem.
(I was gave rep for you before few monts, so i don't know now give for this )
Reply
#9

kurta lбtom szenvedsz angollal
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)