I am a newbie to mysql. Please help. I have a table people like this. The only primary key of people is id
id name age sex
1. John 16 M
2. Peter 18 K
I would like to write some sql to insert some rows to people. But if the name is already exist in the table. I do not insert new row. For example, if I insert the row with the name John and Peter. I do not insert rows. I have a variable name as var_name;
I have search out for the web for a very long time. I use the following sql recommend by the web
INSERT into People(name) values(var_name) where not exists(SELECT name from People
where name = var_name)
But the sql syntax error comes out. Why would this happen. And is there any fast way to acheieve my goal.