Please help with following if statement in MySQL 5.5. I am trying to compare column values to see if they are all equal or different.
SELECT IF(Column1 = Column2 = Column3 = Column4 = Column5, 'SAME', 'Different')
AS ValueStatus
FROM dbs.tabletest
GROUP BY Id
I have also tried the following, however, it only brings one type result as “Different” even when all columns have the same values.
SELECT *,CASE
WHEN Column1 = Column2 = Column3 = Column4 = Column5
Then 'Same'
ELSE 'Different'
END
AS ValueStatus
FROM dbs.tabletest
GROUP BY Id;
Should be
column1 = column2 and column1 = column3 and column1 = column4 and column1 = column5instead.What happened to you is probably you compared
column1tocolumn2, which returnedtrue, then you comparedtruetocolumn3, which yieldsfalse, comparefalsetocolumn4, which also evaluates tofalse, etc.