Lijoyx Posted July 24, 2008 Share Posted July 24, 2008 hai friends, here is my question 1. INSERT INTO category_master (Category_Id, Category_Name) VALUES (1,'Business to Business') WHERE NOT EXISTS(SELECT * FROM category_master WHERE Category_Name = 'Business to Business') 2. IF NOT EXISTS(SELECT * FROM category_master WHERE Category_Name = 'Business to Business') INSERT INTO category_master (Category_Id, Category_Name) VALUES (1,'Business to Business') i am getting an error while executing these queries. whats wrong with it. appreciate each help. Link to comment https://forums.phpfreaks.com/topic/116388-insert-if-exists/ Share on other sites More sharing options...
fenway Posted July 24, 2008 Share Posted July 24, 2008 1. I don't actually know what will happen if you try to do "INSERT INTO... SELECT WHERE 0"... but you're missing "SELECT". 2. That won't work. Why not "INSERT... ON DUPLICATE KEY UPDATE"? Link to comment https://forums.phpfreaks.com/topic/116388-insert-if-exists/#findComment-598576 Share on other sites More sharing options...
accident Posted July 24, 2008 Share Posted July 24, 2008 Or try using the REPLACE function, It will insert a new row if one doesnt exists, if it does exist it will update it Link to comment https://forums.phpfreaks.com/topic/116388-insert-if-exists/#findComment-598605 Share on other sites More sharing options...
fenway Posted July 25, 2008 Share Posted July 25, 2008 Or try using the REPLACE function, It will insert a new row if one doesnt exists, if it does exist it will update it Yes, but that will change the UID and trigger a DELETE. Link to comment https://forums.phpfreaks.com/topic/116388-insert-if-exists/#findComment-599697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.