UBB.Dev
Posted By: dimopoulos Updating data in one table from another - 11/19/2002 5:34 PM
I know how to do this in MSSQL and it is killing me for not being able to find the solution yet.

I created a new table called "inchat". Two fields: C_Username, C_Last.

I also added a new field in the w3t_online table called "O_InChat" (VARCHAR(3) DEFAULT 'no').

I want to run a query that match the C_Username (from the inchat table) with the O_Username (from the w3t_online table) and update the O_InChat field (in the w3t_Online table) to 'yes' for the matched fields.

I came up with this - which doesn't work:
code:

UPDATE inchat
INNER JOIN w3t_online
ON inchat.C_Username = w3t_online.O_Username
SET w3t_online.O_InChat = "yes"


:wallbash: :wallbash:

I don't know what I'm doing wrong....

Thanks in advance

Warm regards

Nikos
Hmmm ... I couldn't find any way to do that either, using only a MySQL query.

Of course, using PHP, you can first do a select query to get the usernames that match across the inchat and w3t_Online tables, and then do the update query on the w3t_Online table using the result from the first query. I could post some code if you want.

Maybe someone else knows a way to do this with a single query.
© UBB.Developers