Skip to content
Advertisement

IF Exists then update in mysql

New to MySQL, need help in translating the next query to MySQL

Advertisement

Answer

Based on the comments posted on your question, here is a code snippet that should answer your need. It works by first checking if the column exists in INFORMATION_SCHEMA, and then dynamically building a SQL query that is prepared, then executed. It the column does not exists, a dummy query is executed instead of the UPDATE. I tested it in this db fiddlde.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement