phpmeh
phpmeh

Reputation: 1792

Is there a difference between := and = with mysql variables?

Is there a difference between @var := 0; and @var = 0; ?

With and without the colon? What does that do?

Upvotes: 1

Views: 86

Answers (1)

Paul Bellora
Paul Bellora

Reputation: 55213

In the case of SET, they are synonymous:

SET @var := 1234;
SET @var = 1234;

But = acts as a conditional operator when used in a SELECT:

SELECT @var := 1234; -- 1234
SELECT @var = 1234;  -- 1

So it's generally best to stick to := for assignment to avoid confusion.

Upvotes: 3

Related Questions