Possible Duplicate:
MySQL: How to add a column if it doesn't already exist?
A tool I use is running this query but it's failing. I'm trying to help debug but cannot figure out what's wrong:
IF EXISTS( SELECT NULL FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = 'TOWNY_RESIDENTS'
AND table_schema = 'minecraft'
AND column_name != 'town-ranks')
THEN
ALTER TABLE TOWNY_RESIDENTS (ADD
`town-ranks` mediumtext,
`nation-ranks` mediumtext
);
The inner select query works fine. It seems the if exists syntax is wrong but I can't figure out how. Examples on website like SO show similar ideas...
The error is:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS( SELECT NULL FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'TOW' at line 1