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
Post a Comment