How to make a check in the query, if the column (field) in the table exists, then it is written to it. Here is my attempt:

INSERT INTO `table` SET `col1` = 1, `col2` = 2, IF(EXISTS(`c`), `col3` = 3) 
  • one
    pull out the table schema, check if there is a column, form the necessary query (apparently you are doing this from php?) and execute it. You can check for the presence of the column at stackoverflow.com/a/7264865/1216425 - teran
  • @teran, I know this way, but I was hoping that there is a simpler method. If there is no other option, you will have to use this one. Thank. - Node_pro
  • And what other option do you have? It simply does not exist within the scope of the ansi-92 capabilities. Or, if you are doing from PHP, then it’s absurd to call the code, catch the "no such field" (in my opinion it’s not possible to do it), if there is no one, then make a record. Nobody does that. - AK
  • @AK, I realized, I thought that the functional is richer - Node_pro

0