Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2012
    Posts
    2

    Unanswered: How to replace data from one col with another col??

    Hi,

    I am a new member. Looking for your help. My problem is-

    there are 4 tables in a database. such as university, student, professor and worker. university table contains fields named- university_name, student_name, professor_name and worker_name. and student, professor and worker tables contain person_id and person_name.

    Now, I want to replace the student_name, professor_name and worker_name data from university table with student table's person_id, professor table's person_id and worker table's person_id.

    How to do that? Please help me.

  2. #2
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    This is a simple "UPDATE" statement, joining the two tables on the person_id.
    Look up the syntax in Books Online.

    Update TableA
    set Value1 = TableB.Value1
    from TableA
    inner join TableB on TableA.FKey = TableB.PKey
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

  3. #3
    Join Date
    Mar 2012
    Posts
    2
    thanks for your reply.

    i have 45000 values. so, if i use

    set value1=tableB.value1

    i have to do it 45000 times. Am i right?

    is there any outher option? im very new so please help me.

    thanks again. im using EMS SQL Manager for MySQL

    Shuvo

  4. #4
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Quote Originally Posted by shuvo_hi View Post
    i have 45000 values. so, if i use

    set value1=tableB.value1

    i have to do it 45000 times. Am i right?
    Absolutely not.
    The method I showed you will update all of them in a single pass. That is what the JOIN is for.
    You need to step back a pace or two and spend half a day reading up on SELECT, INSERT, UPDATE, and DELETE statements. Basic stuff, and without this knowledge you can't go anywhere with SQL.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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