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 > PHP > Transfering data

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-13-10, 09:43
don_log don_log is offline
Registered User
 
Join Date: Jun 2008
Location: pakistan
Posts: 109
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
Reply With Quote
  #2 (permalink)  
Old 06-14-10, 09: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
  #3 (permalink)  
Old 06-15-10, 03:38
don_log don_log is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 08-04-10, 05:28
Nickallen Nickallen is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
hey i was facing same problem. thanks for the reply i will fix it
Reply With Quote
  #5 (permalink)  
Old 08-05-10, 19:50
willowbee willowbee is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
Thank you very much for the solution. Just what I registered for
Reply With Quote
  #6 (permalink)  
Old 10-18-10, 01:23
penthai06 penthai06 is offline
Registered User
 
Join Date: Sep 2010
Posts: 3
Thank you very much
Reply With Quote
Reply

Thread Tools
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