Solved

Need to move multiple columns from one database to another by username

Posted on 2011-09-29
6
300 Views
Last Modified: 2012-05-12
I have two databases and I want to update three of the columns in the second database using three columns from the first by what username it is.

First database

Database1 columns monone, montwo, asignedto

Database2 columns model, size, asignedto

What i need to do is have is monone -> model, montwt-> size, Database1.asignedto->Database2.asignedto by what the asignedto is. I have been researching this and not sure what I am doing.

0
Comment
Question by:maximus81
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 

Author Comment

by:maximus81
ID: 36817999
This is what i have so far and its not working:


UPDATE `monitors` SET model = atsassets.monone, size = atsassets.montwo, asignedto = atsassets.asignedto FROM atsassets where id = atsassets.id

Open in new window

0
 
LVL 24

Expert Comment

by:johanntagle
ID: 36818341
First of all, call them Tables - a database consists of one or more tables.

update Table1 t1, Table2 t2 set t1.monoone=t2.model, t1.montwt=t2.size, t1.asignedto=t2.asignedto where t1.username=t2.username

0
 
LVL 24

Accepted Solution

by:
johanntagle earned 250 total points
ID: 36818565
Sorry, was still sleepy a while back and didn't really read your trial statement.  It should be:

UPDATE monitors, atsassets SET monitors.model = atsassets.monone, monitors.size = atsassets.montwo, monitors.asignedto = atsassets.asignedto where monitors.id = atsassets.id
0
Get Database Help Now w/ Support & Database Audit

Keeping your database environment tuned, optimized and high-performance is key to achieving business goals. If your database goes down, so does your business. Percona experts have a long history of helping enterprises ensure their databases are running smoothly.

 

Author Comment

by:maximus81
ID: 36891384
I actually need to insert instead of update. Here is what I have so far but its not working.

insert into monitors select monone, montwo, asignedto from atsassets
0
 

Author Comment

by:maximus81
ID: 36891397
I got it:

insert into monitors(model, size, asignedto) select monone, montwo, asignedto from atsassets
0
 

Author Closing Comment

by:maximus81
ID: 36891398
Thanks for your help
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Creating and Managing Databases with phpMyAdmin in cPanel.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

752 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