MySQL to select or insert based on condition -


how in single mysql query:

if (select count(*)..)=10   select record same table else   insert record same table 

if want use 1 single sql command (but don't know why) can use stored procedure:

create procedure `select_or_insert`()     modifies sql data     comment 'blah blah' begin     if ((select count(*) `your_table`) = 10)         select ... ... ;     else         insert ... ;     end if; end; 

to invoke procedure issue following command:

call `select_or_insert`(); 

if select executed, statement return resultset.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -