I would like to only insert a row, if the following SELECT returns a 0 or no rows.
Something like:
IF ( SELECT IS 0) THEN INSERT()
how can I do this in MYSQL ?
I just want to do one query instead of this two queries:
$r=mysql_query("SELECT `ID`,`Country` FROM `Users` WHERE `IP`='".$ip."'",$connection);
if(!$r || mysql_num_rows($r) <= 0)
$ir=mysql_query("INSERT INTO `Users` (`IP`,`Country`) VALUES ('".$ip."','".$country."')",$connection);
I think what he may be looking for is something along the lines of this answer:
https://stackoverflow.com/a/8185348
EDIT:
Also incase you ever have problems where you need to remove uniqueness or other constraints:
This will show u all the details of the created table..
then you have to drop via the reference that it has
Ex:
so then you do: