(feed the hungry filters: sql, query) On Monday 27 May 2002 2:14 pm, Victoria Reznichenko wrote:
> ML> Is there a simple way to do something like INSERT IF NOT EXISTS, > ML> other than first doing a SELECT and checking if it returns any rows? > ML> If not, that would be pretty high up on my whish-list : ) > You can use IGNORE keyword in INSERT statement, but it's not quite the > same as "INSERT IF NOT EXIST". If you specify IGNORE, any rows that > duplicate an existing PRIMARY or UNIQUE key in the table > will be ignored in INSERT: Yes, I was aware of the INSERT IGNORE statement, but I've only got one primary/unique key, which happens to be the id. Perhaps I should elaborate further. I've got three tables; ip_name_tbl, loc_tbl and conn_tbl. ip_name_tbl has got fields id, comp_loc, ip_stat_dyn, ip, mac, network, name and comments. loc_tbl has got fileds id, comp_loc and loc_name and conn has got fileds id, wall_nr, hub_switch_nr, comp_id. ip_name_tbl.comp_loc points to loc_tbl.comp_loc=20 conn.comp_id points to ip_name_tbl.id. I want to be sure that while inserting values, say NULL (since id is AUTO_INCREMENT), 1 and "Administration", "administration" isn't already in the table. Rob's idea is of course a solution, but that sort of brings me back to my original question : "is there a -SIMPLE- way"? ; ) INSERT IGNORE wouldn't, if I understood the manual correctly, help me here, since the other rows in the table aren't UNIQUE, no? Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php