1

And if you want to avoid a UNION - not certain of performance here, but this might be better (see fiddle here) - you don't have to query the table twice as for @Akina's query! You might want to check with a large dataset. Create and populate table: CREATE table pat_dis ( p1 INT, p2 INT, dis FLOAT ); INSERT INTO pat_dis VALUES ( 1, 2, 1.1), ( 1, 5, ...


1

This below worked for me: SELECT count(*) INTO @exist FROM information_schema.columns WHERE table_schema = 'mydatabase' and COLUMN_NAME = 'mycolumn' AND table_name = 'mytable' LIMIT 1; set @query = IF(@exist <= 0, 'ALTER TABLE mydatabase.`mytable` ADD COLUMN `mycolumn` MEDIUMTEXT NULL', 'select \'Column Exists\' status');...


Only top voted, non community-wiki answers of a minimum length are eligible