I get the error "IF" is not valid in this position. as soon as I enter an IF in WorkBench. Anyone who knows why? Never get a chance to test this query.
USE arter;
IF (SELECT lokNavn FROM lokalitet WHERE lokNavn='Lodviken') IS NULL THEN
SELECT 1 ELSE SELECT 2 END IF
CodePudding user response:
IF statements can only be used in procedures, not regular queries.
You can use the IF() function or a CASE expression.
SELECT IF(EXISTS(SELECT lokNavn FROM lokalitet WHERE lokNavn='Lodviken')), 1, 2)
