I
I
iRumba2015-05-22 12:25:00
MySQL
iRumba, 2015-05-22 12:25:00

How to update all profile fields in one request if those fields are rows and not columns?

There are tables:
users
[UserId][UserName]
userprofiles
[UserId][Field][Value]
That is, the fields in this
MySQL allows you to execute a query

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Optimus, 2015-05-22
Pyan @marrk2

Loop through all rows and update each

R
Rsa97, 2015-05-22
@Rsa97

If (`UserId`, `Field`) is a unique key, then

INSERT INTO `userprofiles` (`Field`, `Value`) 
    VALUES ('fld1', 'val1'), ('fld2', 'val2'), ... ('fldN', 'valN')
    ON DUPLICATE KEY UPDATE `Value` = VALUES(`Value`)
    WHERE `UserId` = 'uid'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question