Solved

MySQL Insert into table from two tables

Posted on 2011-09-16
8
448 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

I spent nearly three days trying to figure out how incorporate OAuth in Coldfusion for the Eventful API. Hopefully, this article will allow Coldfusion Programmers to buzz through the API when they need to. Basically, what this script does is authori…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 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