#1
  1. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,365
    Rep Power
    24

    Alter/Update 1 table based on another


    Well, I wish to update values on 1 table. It currently holds usernames as the value. I wish to make it alter the username into the userID that matches that username from another table. Table I wish to alter is named Projects and other table that holds logins w/ userID is userPass. How would I pull this off?
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,619
    Rep Power
    4287
    alter the projects table to add the userid column

    then run a joined update to the userpass table matching on username, and update the projects userids

    then -- after you resolve any that weren't matched -- alter the projects table and drop the username
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Super Moderator
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jun 2009
    Location
    Hartford, WI
    Posts
    1,365
    Rep Power
    24
    Very nicely thought. Never crossed my mind to add/remove a column to pull this off. ^_^
    He who knows not that he knows not is a fool, ignore him. He who knows that he knows not is ignorant, teach him. He who knows not that he knows is asleep, awaken him. He who knows that he knows is a leader, follow him.

IMN logo majestic logo threadwatch logo seochat tools logo