tags:

views:

35

answers:

5

Is there an if or if else type statement for mysql.

A: 

There is an if else construct:

IF(value == x, 1, 0)

This returns 1 if value equals x and 0 otherwise.

JoshD
is this to be used inside the mysql coding?
blah
that's an `IF()` function and different from an `IF` statement. Just pointing out.
Ruel
@blah, yes. You can have it as a column in a query. @Ruel: yes. I think this may be what the asker wants, if not, I'll remove it.
JoshD
A: 

As JoshD said, yes there is. Here is the reference in the MySQL Online Manual: http://dev.mysql.com/doc/refman/5.0/en/if-statement.html

Anthony Eden
A: 

There's an IF() function:

IF(expr1,expr2,expr3)

And an IF Statement.

IF search_condition THEN statement_list
    [ELSEIF search_condition THEN statement_list] ...
    [ELSE statement_list]
END IF
Ruel
A: 

Yes, there is. Reference for this and other control flow statements can be found here:

Control Flow Functions

Salman A