ccdavies
ccdavies

Reputation: 1606

Add new rows to a table using id's returned in query

I am using the following query to find all member_id that don't have a row in exp_member_homepage. From the query, 74 results are returned.

select m.member_id
from exp_members m
left outer join exp_member_homepage mh on m.member_id = mh.member_id
where mh.member_id is null

I need to add a new row per member_id to the exp_member_homepage table.

Each row would just include the member_id and the rest of the columns would be default.

Is anyone able to explain how I can do this?

Upvotes: 0

Views: 30

Answers (1)

Dylan Su
Dylan Su

Reputation: 6065

Use insert into select.

insert into exp_member_homepage(member_id)
select m.member_id
from exp_members m
left outer join exp_member_homepage mh on m.member_id = mh.member_id
where mh.member_id is null

Upvotes: 3

Related Questions