What does the := operator mean in mysql?

后端 未结 1 1788
再見小時候
再見小時候 2020-12-24 13:21

I have a mysql table (scho_id,school_name,school_views).

I was looking for a mysql query to get

相关标签:
1条回答
  • 2020-12-24 14:23

    In MySQL, := is an assignment operator:

    SELECT @foo := 'bar';    // variable 'foo' now has value 'bar'
    return value: 'bar'
    

    while = is an equality test:

    SELECT @foo = 'hi mom'; // does variable 'foo' have the value 'hi mom';
    return value: false   ('bar' == 'hi mom' -> false)
    

    Note that you CAN do both equality testing AND assignment with set queries:

    SET @foo = 'bar' = 'baz';
    

    which will cause @foo to be assigned false, the boolean result of 'bar' = 'baz'. It executes as the following:

    SET @foo = ('bar' = 'baz');
    SET @foo = false;
    
    0 讨论(0)
提交回复
热议问题