Skip to content

Instantly share code, notes, and snippets.

@mattvryan
Created October 15, 2014 17:23

Revisions

  1. mattvryan created this gist Oct 15, 2014.
    5 changes: 5 additions & 0 deletions MySQL_INSERT_WHERE_NOT_EXISTS_non_indexed
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    INSERT INTO my_table (unique_but_non_indexed_col1, col2, col3)
    SELECT * FROM (SELECT 'unique_val1', 'val2', 'val3') AS tmp
    WHERE NOT EXISTS (
    SELECT id FROM my_table WHERE unique_but_non_indexed_col1='unique_val1'
    ) LIMIT 1;