I am trying to convert Query from sql server to MySql. My query in Sql is like below:
WITH ChildCategories (ParentID, categoryID, Level)
AS
(
SELECT e.ParentID, e.CategoryID, 0 AS Level
FROM dbo.Category AS e
WHERE ParentID=195
UNION ALL
SELECT e.ParentID, e.CategoryID, Level + 1
FROM dbo.Category AS e
INNER JOIN ChildCategories AS d
ON e.ParentID = d.categoryID
)
Select 195 as categoryID
UNION
select CategoryID from ChildCategories
And I tried to convert above query in MySql like below:
select CategoryID, Name,( @pv:=t.ParentID,t.CategoryID) as ParentID
from (select CategoryID, Name, ParentID from Category order by CategoryID desc) t
join (select @pv:=196)tmp on t.CategoryID=@pv
order by ParentID;
But am getting this error:
Operand should contain 1 column(s)
Can anyone help on this? Thanks in advance.
Copyright Notice:Content Author:「Rekha S」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/38763704/converting-sql-server-query-to-mysql-query