SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Update table from other table

    I'm trying to write an update query.
    I want to read values from one table and insert those values in the second table.
    I tried this
    Code:
    update 
    klassement, deelnemerklasselevel 
    SET 
    klassement.LevelId = deelnemerklasselevel.levelId
    where klassement.deelnemerId = deelnemerklasselevel.deelnemerId 
    AND 
    klassement.KlasseId = deelnemerklasselevel.KlasseId;
    I get message 'Unknown column klassement.klasseId in where clause'

    Can't figure it out.. you ?

  2. #2
    SitePoint Wizard guelphdad's Avatar
    Join Date
    Oct 2003
    Location
    St. Catharines, ON Canada
    Posts
    1,708
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does your version of mysql support multi-table updating? 4.0.4 or higher IIRC.

  3. #3
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi daveman,
    I'm not sure which version it is, but definitely not above 4.xx
    Update is only ment for one table, getting values from another..

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    pookie, just run this query to be sure --
    Code:
    select version()
    yes, you are only updating one table, but unless you're on 4.0+ you cannot mention another table in the UPDATE statement
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Addict
    Join Date
    Dec 2004
    Location
    netherlands
    Posts
    229
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks rudy,

    Version is 3.23.58.
    So is there no way to do this ?

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you may need to write some application logic

    the dreaded query in a loop, i think
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •