0
SELECT last_played INTO @lp FROM sr WHERE creator_id = 1 AND playing = 1 LIMIT 1;
SELECT stream_id INTO @sid FROM account_stream WHERE owner = 1 AND enabled = 1 LIMIT 1;
UPDATE sr SET last_played = 1412259166 WHERE creator_id = 1 AND playing = 1 LIMIT 1;
IF @lp != NULL THEN UPDATE streams SET duration = (duration + (1412259166 - @lp)) WHERE id = @sid LIMIT 1; END IF;

What I am trying to do: when @lp returns something (in other words, when playing is 1 in the first query), then execute the last update streams query.

I get this error in phpmyadmin tho:

1064 - 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 @lp != 0 THEN UPDATE streams SET duration = (duration + (1412259166 - @lp)) W' at line 1

I've never worked with mysql if conditions before, so, can anyone please help me?

2
  • I have learnt that if cannot be used outside procedures. Any suggestions are still welcome. Commented Oct 2, 2014 at 14:47
  • @lp != NULL shouldn't be @lp IS NOT NULL ? Commented Oct 2, 2014 at 15:01

1 Answer 1

1
 UPDATE streams SET duration = (duration + (1412259166 - @lp)) 
 WHERE @lp IS NOT NULL AND id = @sid 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.