Use a select inside of an UPDATE?

r937, is a query somewhat like this going to be possible? I’m just trying to take the first registration date of a user and apply it to their most recent duplicate account.


update users set date = (select date from users where uID = '2637') where uID = '10576';

You shouldn’t call your column DATE, since that is a reserved word in MySQL. Unless you like putting backticks around your column names :wink:

Did you try that query?

Meaning I should add ticks around DATE like the following?

UPDATE users SET ‘DATE’ = (SELECT DATE FROM users WHERE uID = ‘2637’) WHERE uID = ‘10576’;

Backticks, not normal single quotes. But it would be better to give that column another name, like registration_date or whatever.

Can you give me an example? Backticks is a new thing to me.

I don’t have them on my keyboard (and don’t remember the ascii code), but you can google for it :slight_smile:

Backtick: `

US layout keyboards have them on the same button as tilde: ~ in the top left, underneath the ESC button.

So your query would be:

UPDATE users SET `DATE` = (SELECT `DATE` FROM users WHERE uID = '2637') WHERE uID = '10576'; 

(I haven’t tested this, so I don’t know if it works)

But, as Guido mentions, it’s best not to use column names that are reserved words in MySQL.