Reputation: 125
I wanted to ask a question regarding queries, I have two tables,the first table contains column studentid, password, firstname, lastname, middlename the second table contains the password. The first table has an empty password column, so I wanted to copy the data from the second table to transfer it to the first table. However, using this
INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;
did not work :( is there any other option? I also tried importing it through csv still it did not
Upvotes: 0
Views: 32
Reputation: 3924
You will need a unique_id to join the tables on and do an UPDATE
statement. I am assuming your second table (containing passwords) has a student_id on it. So it would look something like this:
update table1 t1 set password = t2.password
from table2 t2
where t2.studentid = t1.studentid
Upvotes: 2
Reputation: 37103
Use the following query:
UPDATE
TABLE2 a INNER JOIN TABLE1 b
ON a.studentid = b.studentid
SET a.password = b.password
Insert query is used to insert a new row into the table instead of updating the column.
Upvotes: 0