1

I have a script that needs to be executed only when some condition is met. For example condition is defined in the following way:

select 1 from table_name where id = 123

if query returns row condition is met, otherwise condition is not met and script should not execute.

How can I implement this conditional logic in an sql script which is then executed with mysql client:

mysql < script.sql

It seems that conditionals are not supported in sql scripts, but probably there are some workarounds (without creating and running procedure).

michael nesterenko
  • 14,222
  • 25
  • 114
  • 182

0 Answers0