We help IT Professionals succeed at work.
Get Started

mysql query issue

CalmSoul asked
Last Modified: 2015-04-20
I am trying to insert list of items from dev.test1 table, but I am struggling with logic ...

Facing  following problems:

- Before insert statements I would like to add "if not exists" - select content from dev.qa_postmetas
- f.URL which I am getting in second query is not coming from correct row in dev.test1 .. I want to select f.URL where f.title = b.title
- Important information here is before executing the second insert query .. we need to get last insert postid in the first query... thats why I am using MAX(b.postid)

INSERT INTO dev.qa_posts (type, categoryid, userid, created, title, content, tags) 
(SELECT  'Q_QUEUED', '1', '3', NOW(), f.title, f.img, f.tagsv 
FROM dev.test1 f) ;
INSERT INTO dev.qa_postmetas (postid, title, content)  
(select MAX(b.postid) , 'qa_q_extra',f.URL 
from dev.qa_posts b 
left JOIN dev.test1 as f on b.postid = f.id) ;

Open in new window

Watch Question
Chief Technical Officer
This problem has been solved!
Unlock 1 Answer and 19 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE