Solved

MySQL Insert into table from two tables

Posted on 2011-09-16
8
445 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
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MYSQL simple update statement 3 46
how do i form the query to get different columns total count 13 42
How many transactions can mysql handle? 3 18
sql_mode 1 15
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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

937 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