I have a table chatmessages
that has a chatId, incomingId, outgoingId column, and I have another table chatmembers
which has a chatId, usersId column. Also another table chat
that contains only the chatId, and the usersId initializer of the chat which is user1
Now, I want to copy the chatId from chatmembers
to chatmessages
where there are the same users inside it, example, the incomingId 83 and outgoingId 81 has the same chatId in chatmembers
I have this query but it doesnt work
UPDATE chatmessages SET chatId =
(SELECT c.chatId FROM chat AS c INNER JOIN (SELECT chatId FROM chatmembers WHERE usersId = incomingId) AS uc ON c.chatId = uc.chatId
INNER JOIN (SELECT chatId FROM chatmembers WHERE companyId = outgoingId) AS cc ON uc.chatId = cc.chatId)
2
Answers
If I understand correctly, you could use
join
s. The following uses MySQL syntax:you must write this query in array and next make execute,
also use double quotes in
like this