INSERT WHERE NOT EXISTS

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • DG

    INSERT WHERE NOT EXISTS

    Hi,

    I'm trying to insert some data into a table and wish to confirm the insert
    is good rather than creating an error. I have tried the following (which
    works on Sybase)

    INSERT customers
    (full_name)
    VALUES
    (''Big Tech Enterprises')
    WHERE NOT EXISTS ( SELECT c.*
    FROM customers c
    WHERE c.full_name = ''Big Tech
    Enterprises')

    Can anyone advise the correct syntax for MySQL?

    Much appreciated,

    David


  • Jeppe Uhd

    #2
    Re: INSERT WHERE NOT EXISTS

    DG wrote:[color=blue]
    > Hi,
    >
    > I'm trying to insert some data into a table and wish to confirm the
    > insert is good rather than creating an error. I have tried the
    > following (which works on Sybase)
    >
    > INSERT customers
    > (full_name)
    > VALUES
    > (''Big Tech Enterprises')
    > WHERE NOT EXISTS ( SELECT c.*
    > FROM customers c
    > WHERE c.full_name = ''Big Tech
    > Enterprises')
    >
    > Can anyone advise the correct syntax for MySQL?[/color]

    Make the c.full_name a unique index and use "INSERT IGNORE ..."

    --
    MVH Jeppe Uhd - NX http://nx.dk
    Webhosting for nørder og andet godtfolk


    Comment

    Working...