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. Quote Link to comment 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"? Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.