x
login about faq Site discussion (meta-askssc)

Help with SQL update query

Hi,

I have 2 sql student tables Student1 and Student2

                    
Student1
                    
Student ID   Name    Test taken     Test Date      Test Result
                    
1            Sam     TB             05/23/2010     Pending
                    
1            Sam     MMR            06/20/2010     Pending
                    
2            Tom     MMR            07/14/2010     Pending
                    

                    
Student2
                    
Student ID   Name    Test taken     Test Date      Test Result
                    
1            Sam     TB             05/23/2010     Pass
                    
2            Tom     MMR            07/14/2010     Pass
                    

As you can see, both the tables have no primary key and some entries in Student1

are updated in Student2

I want to write an sql query that will update all the matching Student1 entries from Student1.

For the entries to match, the Student ID, Name, Test taken and Test Date fields should match.

Then for these matching entries we check if the Test Result has been updated and update the same

in the table Student1.

So, our Student1 table after executing the query should be

                    
Student1
                    
Student ID   Name    Test taken     Test Date      Test Result
                    
1            Sam     TB             05/23/2010     Pass
                    
1            Sam     MMR            06/20/2010     Pending
                    
2            Tom     MMR            07/14/2010     Pass
                    

Someone please help me write this query.

more ▼

asked Sep 21 '10 at 11:09 AM in Default

lazyme gravatar image

lazyme
1 1 1 1

(comments are locked)
10|1200 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments



Facebook logo Follow Ask SSC on Facebook
Find Ask SSC on Google+
linkedin logo Find us on LinkedIn

Topics:

x600
x321
x113

asked: Sep 21 '10 at 11:09 AM

Seen: 568 times

Last Updated: Sep 21 '10 at 11:09 AM

Copyright © 2002-2012 Simple Talk Publishing. All Rights Reserved. If you have any queries, please contact the site administrators.
Ask SQL Server Central is a community service provided by Red Gate.