1

I have 2 tables, cce_sa_fa & cce_activity

I used the following line to get the cce_sa_fa not included in cce_activity

select id from cce_sa_fa where id NOT IN (select safa from cce_activity)

Using this query, I got 113 rows. Now I need to INSERT these ids into cce_activity. Here the id needs to be inserted and other columns are with fixed value. Usual insert query for cce_activity is as follows.

INSERT INTO `cce_activity` (`id`, `safa`, `name`, `mark`) VALUES (NULL, '"+id_of_ cce_sa_fa+"', 'Activity 1', '0');

How can I insert all the ids from the SELECT query to INSERT into cce_activity

asked Feb 18, 2017 at 5:58

1 Answer 1

1

if columns same:

INSERT INTO cce_activity select * from cce_sa_fa where id NOT IN (select safa from cce_activity)

if not, something like:

INSERT INTO cce_activity (col1, col2, col3) select col1, col2, col3 from cce_sa_fa where id NOT IN (select safa from cce_activity)
answered Feb 18, 2017 at 6:08

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.