SQL PHP HTML ASP JavaScript articles and free scripts to download
SQL

Updating another table with data from main table

It is often required to use one table and update data in another table. The second table columns gets updated by taking data from first table. Let us say we have one table where students test marks are stored along with other details in other columns. We can collect only the test data and keep them in a separate table. Let us call this second table as student mark table. Both the tables will have student id field which we will be using to link both tables

update s_mark,s_test set mark= test1 where s_mark.s_id=s_test.s_id

Here are both tables for you.

CREATE TABLE `s_mark` (
`s_id` int(3) NOT NULL,
`mark` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Dumping data for table `s_mark`
--
INSERT INTO `s_mark` VALUES (1, 7);
INSERT INTO `s_mark` VALUES (2, 6);
-- --------------------------------------------------------
--
-- Table structure for table `s_test`
--
CREATE TABLE `s_test` (
`s_id` int(3) NOT NULL,
`test1` int(3) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer