Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109

    Unanswered: Transfering data

    I have a problem

    i have 2 tables one is std_info

    which have many column like name,email,adress,date of birth, but the main column in his information is
    PHP Code:
    stnd_id,stnd_class,stnd_fees 
    and i have another table
    PHP Code:
    std_fees_staging 
    which have also many columns and main columns are
    PHP Code:
    stnd_id,stnd_class,stnd_fees 
    i want to transfer these three column data of std_info in to std_fees_staging so how do i write the query of it please suggest me the sql query of this thanks for reply

  2. #2
    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

  3. #3
    Join Date
    Jun 2008
    Location
    pakistan
    Posts
    109
    Thanks i got the solution already but very thanks to tell me cause other came this forum and get help

  4. #4
    Join Date
    Aug 2010
    Posts
    1
    hey i was facing same problem. thanks for the reply i will fix it

  5. #5
    Join Date
    Aug 2010
    Posts
    1
    Thank you very much for the solution. Just what I registered for

  6. #6
    Join Date
    Sep 2010
    Posts
    3
    Thank you very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •