Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Oracle SQL Query 1

Status
Not open for further replies.
Joined
Nov 5, 2001
Messages
339
Location
GB
I am trying to update a field in one table with a value from another table and don't know the syntax.

Table1: PEOPLE
Table2: DATA_IMPORT

tables link on NI_Number field

Want to copy Data_Import.Status field into People.Status field where the NI numbers match.

Can anyone help please? Steve Phillips, Crystal Consultant
 
update people p set p.status = (select d.status from data_import d where d.ni_number = p.ni_number); I tried to remain child-like, all I acheived was childish.
 
Steve,

Try something like:

update people
set people.statue = data_import.status
where people.ni_number = data_import.ni_number;

Regards,

Naith, Crystal Consultant.
 
Just what I was after Jimbo.

The "select" bit was returning multiple rows so I changed it to a "select max(d_status)" statement and it works perfectly.

Thanks again. Steve Phillips, Crystal Consultant
 
Use jimbopalmer's solution..

One caveat: If there is more than one record whose ni_number matches in the data_import table, the insert wil fail with a 'query returns more than 1 row' error..

This method will only work with properly modelled tables..
( One to One, not One to Many )

hth
[profile]
 
Gee, things move fast in this forum..

Using Max may not give you what you want - you may want to remove the duplicates...The Max value might not be the 'correct' one, depending on how the data_import table is populated..

[profile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top