View Single Post
  #2 (permalink)  
Old 06-14-10, 08:32
saviola saviola is offline
Registered User
 
Join Date: Jun 2010
Posts: 6
UNION allows you to combine the results from different tables. If you want to view all records(repeated) in both tables use UNION ALL :
Code:
SELECT stnd_id, stnd_class, stnd_fees  
   FROM std_info
     UNION
SELECT std_fees_staging
    FROM stnd_id, stnd_class, stnd_fees
To get row-ids from std_info which values (combination of the three values in row) isn't in std_fees_staging, i think you have to do something like this :
Code:
SELECT stnd_id FROM std_info
WHERE stnd_id NOT IN (SELECT DISTINCT stnd_id FROM std_info AS std, std_fees_staging AS stdfs 
WHERE (std.stnd_id = stdfs.stnd_id AND std.stnd_class = stdfs.stnd_class AND std.stnd_fees =stdfs.stnd_fees))
To get row-ids from std_info which values (not combination of the three values in row, just one or more is differebt) isn't in std_fees_staging
Code:
SELECT stnd_id FROM std_info
WHERE stnd_id NOT IN (SELECT DISTINCT stnd_id FROM std_info AS std, std_fees_staging AS stdfs 
WHERE (std.stnd_id = stdfs.stnd_id OR std.stnd_class = stdfs.stnd_class OR  std.stnd_fees =stdfs.stnd_fees))
When you find which rows not exist in both tables, you can fetch this data from std_info and insert in std_fees_staging.

If you are sure that there is no repetition and just want to transfer value of these three columns from one table to another, you can do this:

Code:
INSERT INTO std_fees_staging(stnd_id, stnd_class, stnd_fees) SELECT stnd_id, stnd_class, stnd_fees FROM std_info
Reply With Quote