I have a database where i put some societies and their employees. The thing is that two societies can have an employe with the same name (but they are different person). So when I want to insert an employe (stagiaire) I try to check if it exists for this society. Here is my query :
INSERT INTO stagiaire(Nom,Email,Telephone,IDSociete )
VALUES('Paul','ppk@mail.fr','0000000000','7' )
WHERE(SELECT stagiaire.ID FROM stagiaire
LEFT JOIN societe ON stagiaire.IDSociete = societe.ID
WHERE stagiaire.Nom = 'Paul' AND societe.NomSoc = 'PachaKebab') NOT EXISTS
Heres 'Paul' already exists in the society 'Promoplantes' and I have another 'Paul' in the society 'PachaKebab' (ID = 7) the one I try to insert.
I tried few things like IF NOT EXISTS
the my INSERT query (between begin/end) but it seems like phpMyAdim (SQL Server that i use) can't unserstand the IF NOT EXISTS
or NOT EXISTS
code.
Is that true ? Or do I have an error in my code that I dont see ?