Solved

MySQL Insert into table from two tables

Posted on 2011-09-16
8
449 Views
Last Modified: 2012-05-12
I need help inserting ContactID  from a contacts (table) into a lead_tracking (table) with the same field name of ContactID.

I need to use some sort of conditional logic to parse out the records that have a ContactID with the ContactStatusID = 2 in the contacts table. With that information I need to have two preset values for two addtional fields in the lead_tracking table that have nothing to do with the contacts table... I hope to god that makes sense because my head is spinning.

See code for my wrong example


INSERT INTO lead_tracking
 (ContactID)
 SELECT ContactID
 FROM contacts
 WHERE ContactStatusID =2

// in addition add a preset values of Lead_typeID = 2 & Lead_progressID = 5 ( into the lead_tracking  table)

Open in new window

0
Comment
Question by:jasch2244
[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
8 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
ID: 36552232
If I'm understanding correctly, and you want to insert just hard code the values. This would insert the values 2 and 5 for all records.

INSERT INTO lead_tracking (ContactID, Lead_typeID, Lead_progressID )
SELECT ContactID, 2, 5
FROM    contacts
WHERE ContactStatusID =2

0
 
LVL 52

Expert Comment

by:_agx_
ID: 36552236
Gah ... that didn't make sense what I meant to say was :

"If I'm understanding correctly, just hard code the values. This would insert the values 2 and 5 for all records."
0
 
LVL 82

Assisted Solution

by:hielo
hielo earned 250 total points
ID: 36552243
If this gives you the results you want:
SELECT contacts.ContactID,2,5
 FROM contacts
 WHERE contacts.ContactStatusID =2

backup your table and try:


INSERT INTO lead_tracking (ContactID,Lead_typeID,Lead_progressID)
 SELECT contacts.ContactID,2,5
 FROM contacts
 WHERE contacts.ContactStatusID =2
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 52

Expert Comment

by:_agx_
ID: 36553112
@jasch2244 - Did you miss my answer? I thought that's exactly what I suggested first.
0
 
LVL 1

Author Comment

by:jasch2244
ID: 36598549
Yeah, I'm not sure what happened there. I don't remember you having the INSERT INTO lead_tracking (ContactID,Lead_typeID,Lead_progressID)... I remember seeing " INSERT INTO lead_tracking" but not the later.

Sorry about that
0
 
LVL 52

Expert Comment

by:_agx_
ID: 36599704
Ok, thanks.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This post contains step-by-step instructions for setting up alerting in Percona Monitoring and Management (PMM) using Grafana.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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