Need some urgent help in using UPDATE command in SQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Need some urgent help in using UPDATE command in SQL

Post by legend986 »

I have two tables:

Table Name: table1
Table Rows: a b

Table Name: table2
Table Rows: a b c d e f

Initially c of table2 is empty. I want to actually fill it up from table1 using some statement like:

Code: Select all

UPDATE table2 SET c={SELECT a FROM table1 WHERE b=d}

Where d belongs to table2.

Is this possible?
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

Change the { into ( and } into ). Next question, have you tried it? I suspect if you had you wouldn't be asking the question ;) ( hint. it's called subqueries if you're using google to find more information about it ).
User avatar
legend986
Forum Contributor
Posts: 258
Joined: Sun Jul 15, 2007 2:45 pm

Post by legend986 »

I was actually typing that I figured out the solution when I got your reply :) Thanks for the information... Realized my mistake...
Post Reply