SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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.

    Thanks!

    Code MySQL:
    update users set date = (select date from users where uID = '2637') where uID = '10576';
    Convert your dollars into silver coins. www.convert2silver.com

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    You shouldn't call your column DATE, since that is a reserved word in MySQL. Unless you like putting backticks around your column names

    Did you try that query?

  3. #3
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Meaning I should add ticks around DATE like the following?

    UPDATE users SET 'DATE' = (SELECT DATE FROM users WHERE uID = '2637') WHERE uID = '10576';
    Convert your dollars into silver coins. www.convert2silver.com

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Backticks, not normal single quotes. But it would be better to give that column another name, like registration_date or whatever.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2004
    Location
    Provo, UT
    Posts
    858
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you give me an example? Backticks is a new thing to me.
    Convert your dollars into silver coins. www.convert2silver.com

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    I don't have them on my keyboard (and don't remember the ascii code), but you can google for it

  7. #7
    SitePoint Wizard bronze trophy Immerse's Avatar
    Join Date
    Mar 2006
    Location
    Netherlands
    Posts
    1,661
    Mentioned
    7 Post(s)
    Tagged
    1 Thread(s)
    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:

    Code sql:
    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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •