Solved

update values from one table to a similar table

Posted on 2013-05-26
12
279 Views
Last Modified: 2013-05-28
delimiter $$

CREATE TABLE `email_doc` (
  `id` int(11) NOT NULL auto_increment,
  `unix_timestamp` bigint(20) default NULL,
  `from_email` varchar(200) default NULL,
  `from_name` varchar(200) default NULL,
  `to_email` varchar(200) default NULL,
  `to_name` varchar(200) default NULL,
  `subject` varchar(400) default NULL,
  `body` varchar(4000) default NULL,
  `real_id` varchar(30) default NULL,
  `checked` int(11) default NULL,
  `me_description` varchar(9000) default NULL,
  `client_description` varchar(4000) default NULL,
  `sms_type` tinyint(4) default NULL,
  `client_start` datetime default NULL,
  `client_end` datetime default NULL,
  `client_total` int(11) default NULL,
  `me_start` datetime default NULL,
  `me_end` datetime default NULL,
  `me_total` int(11) default NULL,
  `real_timestamp` int(11) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `unix_timestamp` (`unix_timestamp`)
) ENGINE=MyISAM AUTO_INCREMENT=1758 DEFAULT CHARSET=utf8$$



want to copy me_start, me_end,me_total into email_doc_similar where unix_timestamp is the same
0
Comment
Question by:rgb192
  • 6
  • 6
12 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
update email_doc_similar a set a.me_start = b.me_start
inner join email_doc b on a.id= b.id
where
a.unix_timestamp = b.unix_timestamp

------- assuming the table structure is same for both tables

repeat update statement for me_end & me_total
0
 

Author Comment

by:rgb192
Comment Utility
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'inner join email_doc  b on a.id= b.id where a.unix_timestamp = b.unix_times' at line 2
0
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
update email_doc_similar a
set
a.me_start = b.me_start
a.me_end = b.me_end
a.me_total = b.me_total
from
email_doc_similar a
inner join
email_doc b on a.id= b.id
where
a.unix_timestamp = b.unix_timestamp


try this
0
 

Author Comment

by:rgb192
Comment Utility
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a.me_end = b.me_end a.me_total = b.me_total from email_doc_test a inner join ema' at line 4
0
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
update email_doc_similar a
set
a.me_start = b.me_start
from
email_doc_similar a
join
email_doc b on a.id= b.id
where
a.unix_timestamp = b.unix_timestamp

how abt this?
0
 

Author Comment

by:rgb192
Comment Utility
Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from email_doc_similar a join email_doc b on a.id= b.id where a.unix_timestam' at line 4
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
update email_doc_similar a , email_doc b
set
a.me_start = b.me_start
where
a.id= b.id
and
a.unix_timestamp = b.unix_timestamp


lets keep it simple ....
0
 

Author Comment

by:rgb192
Comment Utility
0 row(s) affected Rows matched: 0  Changed: 0  Warnings: 0
0
 
LVL 16

Accepted Solution

by:
santoshmotwani earned 500 total points
Comment Utility
update email_doc_similar a , email_doc b
set
a.me_start = b.me_start
where
a.unix_timestamp = b.unix_timestamp
0
 

Author Comment

by:rgb192
Comment Utility
0 row(s) affected Rows matched: 0  Changed: 0  Warnings: 0
0
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
as you said you want to copy contents from email_doc to email_doc_similar right?

if yes, please post the output for :

select * from email_doc

Thanks
0
 

Author Closing Comment

by:rgb192
Comment Utility
this works,
comparing two tables and doing updates

thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Join & Write a Comment

Introduction In this installment of my SQL tidbits, I will be looking at parsing Extensible Markup Language (XML) directly passed as string parameters to MySQL 5.1.5 or higher. These would be instances where LOAD_FILE (http://dev.mysql.com/doc/refm…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now