Question : How to write a correlated query between tables

I have two tables in sql server 2008.  One is a customer table and the other is a customers spouse table. Each customer has notes which I need to ensure also exist on the spouse note. That is I need ensure the spouse has all the notes that were added to the customer record.  How do I write a query to show me spouses which dont have the note of the related customer? Of course then I need the note and the spouse ID so I can add them to the database.

The spouse and the customer are linked (ie there is a customer id on the spouse table pointing back to who their spouse is).  I believe the technique for this is to use a correlated query but im not sure.  Below are the two tables (if you cant see them because of formatting I've uploaded an excel file with the tables):

CUSTOMER TABLE            
Cust ID      customer                 Note
1               John                    Email Contact Only
1               John                    Phone After 5pm
1               John                    Don’t Snail Mail
2               Peter                   Don’t Snail Mail
3               Eddy                   Call on Cell Phone
3               Eddy                   Forward to VP
4               Tim                     Email Contact Preferred
4               Tim                     Phone After 5pm

CUSTOMERSPOUSETABLE                  
CustomerSpouseID          SpouseName         RelatedtoCustomerID                  Note
57                                  Jane                        1                                             Phone After 5pm
58                                  Mary                       2                                             NULL
59                                  Fran                        3                                             Forward to VP
60                                  Barbara                   4                                             Email Contact Preferred


Attachments:
 
 

Answer : How to write a correlated query between tables

get one www.godaddy.com. Otherwise you users are going to get prompted ever 5 minutes. Will SBS 2003 you could get away with not having one and just click continue when the certificate error came up. but with SBS 2008 you have got to really have it or you will get loads of problems.
a SSL cert is only about $25 per year.
Random Solutions  
 
programming4us programming4us