I'm trying to check weather thw column exists or not
IF (SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'tb_consumer' AND COLUMN_NAME='businness_id' > 0 ) THEN
PRINT 'test'
Whats wrong with above sql? getting error as
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 (Select COUNT(*) From INFORMATION_SCHEMA.COLUMNS Where TABLE_NAME = 'tb_consu' at line 1
New to SQL. Thanks for any help,
Version of MySql is 5.X
You can fix the query by moving the closing paren:
A better way to write the condition is using
exists
: