If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Update Query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-01-04, 15:38
funky funky is offline
Registered User
 
Join Date: Apr 2004
Posts: 3
Update Query

Hi

I am trying to do an update query in MS Access using SQL

I have two tables Employees and Salaries.

Employees
Emp ID PK
Dept
Postion
SALARY

Salaries
Emp Id PK
HRLY rate
SALARY

I am trying to update the salary figure from the Salaries table into the employee table using sql. How would I do this?
Reply With Quote
  #2 (permalink)  
Old 04-02-04, 10:31
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Update Query

On Oracle I would do:

update employees e
set salary = (select salary from salaries s where s.emp_id = e.emp_id)
where emp_id in (select emp_id from salaries);

The final WHERE clause is to prevent overriding existing salary values with NULL where no matching salaries row exists. Omit the WHERE clause if that is what you would want to do.
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
  #3 (permalink)  
Old 04-03-04, 03:00
funky funky is offline
Registered User
 
Join Date: Apr 2004
Posts: 3
No Joy it told me to use an updatable query (which I had done!)
Reply With Quote
  #4 (permalink)  
Old 04-03-04, 07:15
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
joined update syntax varies from database to database

in sql server, it's
PHP Code:
update table1
   set fldx 
t2.fldy
  from table1 t1
inner
  join table2 t2
    on t1
.keyfld t2.keyfld
 where t2
.fldz 'foo' 
whereas in access it's
PHP Code:
update table1
inner 
  join table2 
    on table1
.keyfld table2.keyfld
   set table1
.fldx table2.fldy
 where table2
.fldz 'foo' 
so for your example you would write
PHP Code:
update Employees
inner 
  join Salaries 
    on Employees
.EmpID Salaries.EmpID
   set Employees
.SALARY Salaries.SALARY 
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 04-04-04, 01:38
funky funky is offline
Registered User
 
Join Date: Apr 2004
Posts: 3
Unhappy

Still won't work!

I am being asked to supply a parameter value for employees.salary and then it tells me the table field is not updateable
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On