0

Im trying to doing a sql query that is not working, I would like to add one element to a table only and only if that value is not in the table, something like that:

IF EXISTS (Select `id` from `artists` Where `artist`='"$artist"') Do Nothing ELSE Insert into `artists` (`artist`) values('".$artist."') 

What is the best way to do that?

PS: I have tried to look for that information by google and in the forum, but I dont understand the idea

Thank you very much in advance

PS2: Sorry, Its a MYSQL database

1
  • Maybe a duplicated entry: see here Commented Sep 25, 2013 at 15:28

1 Answer 1

2

What about using IF NOT EXISTS...

Something like:

IF NOT EXISTS (Select `id` from `artists` Where `artist`='"$artist"') Insert into `artists` (`artist`) values('".$artist."') 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.