SQL PHP HTML ASP JavaScript articles and free scripts to download
 

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;




Further readings
Changing structur of the table bu alter query
Create table query with if exists sql with php script
Creating a new table by using data from one table
Change the name of a table
Copying data from one table to another table
Delete records from a table with conditinos
Delete table by using DROP sql
Updating another table with data from main table
Update SQL commands
Inserting SUM, AVG data from one table column to other using group by command
Table Records are downloaded as .csv file
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

Join Our Email List
Email:  
For Email Newsletters you can trust
Modify Table
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

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