Jump to content

Update One Table from Data in Another Table


transfield

Recommended Posts

Hello,

 

I have 2 tables. The structures are below:-

 

CREATE TABLE IF NOT EXISTS `dcp_reports_raw` (
`id` int(6) NOT NULL auto_increment,
`club_num` int(10) NOT NULL,
`club_name` varchar(60) NOT NULL,
`mship_base` int(3) NOT NULL,
`mship_todate` int(3) NOT NULL,
`dcp_todate` int(2) NOT NULL,
KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;

CREATE TABLE IF NOT EXISTS `dcp_reports` (
`id` int(6) NOT NULL auto_increment,
`club_num` int(10) NOT NULL,
`club_name` varchar(60) NOT NULL,
`mship_base` int(3) NOT NULL,
`mship_todate` int(3) NOT NULL,
`dcp_todate` int(2) NOT NULL,
`mship_lastweek` int(3) NOT NULL,
`dcp_lastweek` int(2) NOT NULL,
`to_email` varchar(100) NOT NULL,
`from_email` varchar(50) NOT NULL,
`message` varchar(1000) NOT NULL,
`database_lastupdated` date NOT NULL,
`email_lastsent` date NOT NULL,
`expiry` date NOT NULL,
KEY `id` (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;

I want to :-

 

1. update dcp_reports.mship_todate with the data from dcp_reports_raw.mship_todate provided that the values of dcp_reports.club_num and dcp_reports_raw.club_num are the same.

 

2. update dcp_reports.dcp_todate with the data from dcp_reports_raw.dcp_todate provided that the values of dcp_reports.club_num and dcp_reports_raw.club_num are the same.

 

If both item 1 and 2 can be combined in 1 query, so much the better. Otherwise, I'm okay with 2 separate queries.

 

Could you show me how to write the code in PHP or MySql please?

 

Thanks.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.