Solved

MySQL Insert into table from two tables

Posted on 2011-09-16
8
442 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
  • 4
8 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 250 total points
Comment Utility
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_
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 52

Expert Comment

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

Author Comment

by:jasch2244
Comment Utility
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_
Comment Utility
Ok, thanks.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

11 Experts available now in Live!

Get 1:1 Help Now