Need to insert two columns from one table another only if th

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
barb woolums
Forum Contributor
Posts: 134
Joined: Sun Feb 08, 2009 9:52 pm

Need to insert two columns from one table another only if th

Post by barb woolums »

I want to enhance this mysql sql statement so that the two columns are only inserted if they don't already exist as a pair in the table.

insert into ingredient_owner (ingredient,owner) select distinct ing, (select owner from recipe where id=recipe_ing.recipe) as owner from recipe_ing where ing is not null;
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Need to insert two columns from one table another only i

Post by Celauran »

Wouldn't a composite index be the easiest solution?
User avatar
barb woolums
Forum Contributor
Posts: 134
Joined: Sun Feb 08, 2009 9:52 pm

Re: Need to insert two columns from one table another only i

Post by barb woolums »

Done - thanks
Post Reply