Search code examples
mysqlmysql-error-1064

How to Set ouput of select in variable by mysql?


i want to count product id set to variable @x. in query of phpmyadmin no procedure or function. but error

set @x=70489;
    set @y = select count(`product_id`) from `oc_product` where  `language_id`=2 and `product_id`=@x;

    select @x;
    SELECT @y;

SQL query: Documentation set @x=70489 set @y = select count(product_id) from oc_product where language_id=2 and product_id=@x; MySQL said: Documentation 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 'set @y = select count(product_id) from oc_product where `langua' at line 2


Solution

  • add () in start and end of select.

    set @x=70489;
    set @y = (select COUNT(*) from `oc_product` where  `language_id`=2 and `product_id`= @x);
    
    SELECT @x;
    SELECT @y;