well this is if im not mistaken to copy the whole data in a table to another table
INSERT into destination_table SELECT * from source_table;
but how about if i want to copy a data from table a to table b?
let say that we know the username and we want to copy his real name to another table.....
well i got this one but it wont work.
$sql = "UPDATE details,mn SET details.name=mn.name, where details.idnum=mn.idnum";
$result=mysql_query($sql) or die("Died inserting login info into db. Error returned if any: ".mysql_error());
it gives out an error
Died inserting login info into db. Error returned if any: You have an error in your SQL syntax near 'mn SET details.name=mn.name, where details.matric=mn.matric' at line 1
anyone?..
how to copy a data from a table to anotehr table?
Moderator: General Moderators
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Yes you can:Coco wrote:can you have a select in an insert query?
in mysql 3?
http://www.mysql.com/doc/en/INSERT_SELECT.html
Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Re: how to copy a data from a table to anotehr table?
It probably isn't working because you're most likely using MySQL version 3 and that syntax is only supported by MySQL version 4.0.4 or above:omegahawk wrote:well i got this one but it wont work.
$sql = "UPDATE details,mn SET details.name=mn.name, where details.idnum=mn.idnum";
$result=mysql_query($sql) or die("Died inserting login info into db. Error returned if any: ".mysql_error());
it gives out an error
Died inserting login info into db. Error returned if any: You have an error in your SQL syntax near 'mn SET details.name=mn.name, where details.matric=mn.matric' at line 1
http://www.mysql.com/doc/en/UPDATE.html
You'd have to find another - most likely less simple - solution. Although it's normally not good practise to have identical information stored in different tables.
Mac