1

I want to make an if else query in a mysql query. Unfortunately I do not know how to do it right. Can someone please explain?

How can I make a query like this:

if s_table.column1 = s_table.column2
set .s_table.column1 = 1
else
set .s_table.column1 = 2
end if
Scath
  • 3,777
  • 10
  • 29
  • 40
n8lauscher
  • 63
  • 6
  • Possible duplicate of [How do I perform an IF...THEN in an SQL SELECT?](https://stackoverflow.com/questions/63447/how-do-i-perform-an-if-then-in-an-sql-select) – Scath Jul 28 '17 at 18:18
  • What is wrong with your query? – Eric Jul 28 '17 at 18:23

1 Answers1

0
IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF

I think you are missing the THEN

Can be found on there documentation page : https://dev.mysql.com/doc/refman/5.7/en/if.html

Josh Adams
  • 2,113
  • 2
  • 13
  • 25