By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,107 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

transfer

computerfox
100+
P: 278
hey guys, i had this working before, but when i added another bit, it stopped and now i can't get it to work again

Expand|Select|Wrap|Line Numbers
  1. //Put data into right tables
  2.  
  3. mysql_query("SELECT* FROM inprogress");
  4. mysql_query("INSERT INTO complete SELECT* FROM inprogress WHERE Status='Y' ");
  5.  
  6.  
  7. mysql_query("SELECT* FROM complete");
  8. mysql_query("INSERT INTO inprogress SELECT* FROM complete WHERE Status='N' ");
  9.  
is this not how you transfer data?
Apr 14 '10 #1

✓ answered by chathura86

yep that means your tables are not compatible,

here for an example
INSERT INTO complete SELECT* FROM inprogress WHERE Status='Y'

in this query

SELECT* FROM inprogress WHERE Status='Y will return all the columns
from inprogress table,

and then it will try to insert them to complete table

so the complete table should have the same number of columns and
their data types should be compatible also

and it is possible to insert selected values only

insert into (col1, col2, cols3) (select col1, col2, col3)

as the summery

the number of columns in the insert and select should be equal and their
data types should be compatible.

http://mysql-tips.blogspot.com/2005/...t-example.html
http://dev.mysql.com/doc/refman/5.1/...rt-select.html

Regards

Share this Question
Share on Google+
4 Replies


chathura86
100+
P: 227
you SQLs are seems to be ok.

anyway mysql_query("SELECT* FROM complete");
and mysql_query("SELECT* FROM inprogress");
is not required unless you are executing for another reason.

but i hope that your table structures are compatible.

what is the error message you are getting.

Regards
Apr 14 '10 #2

computerfox
100+
P: 278
not really getting any errors through the web page, but when i tested it in mysql i got something about cols not matching value rows in line 1
Apr 14 '10 #3

computerfox
100+
P: 278
nevermind. careless mistake. thank you anyways :)
Apr 14 '10 #4

chathura86
100+
P: 227
yep that means your tables are not compatible,

here for an example
INSERT INTO complete SELECT* FROM inprogress WHERE Status='Y'

in this query

SELECT* FROM inprogress WHERE Status='Y will return all the columns
from inprogress table,

and then it will try to insert them to complete table

so the complete table should have the same number of columns and
their data types should be compatible also

and it is possible to insert selected values only

insert into (col1, col2, cols3) (select col1, col2, col3)

as the summery

the number of columns in the insert and select should be equal and their
data types should be compatible.

http://mysql-tips.blogspot.com/2005/...t-example.html
http://dev.mysql.com/doc/refman/5.1/...rt-select.html

Regards
Apr 14 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.