1
DECLARE vote_id INT;
    select id from votes where votes.question_id = question_id and vote_type_id = 3 into vote_id;

    if vote_id is null then
      ...do A
    else
      ...do B
    end if;

the condition should be true and execute A part of code but always execute B part.
How to use select with if statement? Thank you very much.

2
  • 1
    Maybe vote_id is never null as per your query? Commented Dec 28, 2011 at 9:35
  • I execute the 'select id...' in mysql and return id Commented Dec 28, 2011 at 9:39

1 Answer 1

1

try select id from votes where votes.question_id = question_id and votes.vote_type_id = 3 into vote_id;

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.