List:General Discussion« Previous MessageNext Message »
From:Adaikalavan Ramasamy Date:July 26 2004 5:24pm
Subject:Re: INSERT if record NOT EXISTS
View as plain text  
Yes, this does what I want and does not produce an error (which caused
the remaining MYSQL syntax not to be executed). The firstname, lastname
was for example only. In my problem, these are two different identifiers
so I am not worried about multiple dual identifiers.

Thanks to Keith Ivey, Alec Cawley, Gerald Clark and Michael Dykman for
helping with this problem.

I learnt a lot from the list today. Thanks!

Regards, Adai.


On Mon, 2004-07-26 at 18:04, Keith Ivey wrote:
> Adaikalavan Ramasamy wrote:
> 
> >This naive syntax does not work :
> >IF EXISTS (SELECT myID FROM tb WHERE firstname='Jack' AND
> >lastname='Doe') ELSE (INSERT INTO tb(firstname, lastname) VALUES
> >('Jack', 'Doe');
> >
> Assuming you have the unique index on (firstname, lastname), just do
> 
>    INSERT IGNORE INTO tb (first_name, lastname) VALUES ('Jack', 'Doe');
> 
> But how are you planning to handle multiple people named Jack Doe?

Thread
INSERT if record NOT EXISTSAdaikalavan Ramasamy26 Jul
  • Re: INSERT if record NOT EXISTSAlec.Cawley26 Jul
  • Re: INSERT if record NOT EXISTSgerald_clark26 Jul
  • Re: INSERT if record NOT EXISTSMichael Dykman26 Jul
    • Re: INSERT if record NOT EXISTSAdaikalavan Ramasamy26 Jul
      • Re: INSERT if record NOT EXISTSMarc Slemko26 Jul
  • Re: INSERT if record NOT EXISTSHarald Fuchs27 Jul
Re: INSERT if record NOT EXISTSAdaikalavan Ramasamy26 Jul
  • Re: INSERT if record NOT EXISTSAlec.Cawley26 Jul
  • Re: INSERT if record NOT EXISTSKeith Ivey26 Jul
    • Re: INSERT if record NOT EXISTSAdaikalavan Ramasamy26 Jul