Converting Sql server query to MySql query
NickName:Rekha S Ask DateTime:2016-08-04T17:36:59

Converting Sql server query to MySql query

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

More about “Converting Sql server query to MySql query” related questions

Converting Sql server query to MySql query

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 FR...

Show Detail

Converting mysql query to SQL Server

I have a sql query from mysql which converts the value which is saved in decimal into dot (.). How do I convert it to support SQL Server ? It is the SUM(IF -- Query. SELECT routines.date, routines...

Show Detail

Converting MySQL Simple Query to SQL Server

I have Completed MySQL Simple Query, SELECT acc_trans.VoucherNumber, acc_trans.EntryDate, acc_trans.Debit, acc_trans.Credit, @Balance:= round(@Balance,2) + acc_trans.Debit - acc_trans....

Show Detail

MS SQL Server Query Date functions to MySQL

I have this MS SQL Server query: SELECT DATEPART(MONTH, si.score_date), MAX(si.score_value) FROM score_info AS si WHERE si.score_date >= DATEADD(MONTH, -3, DATEADD(MONTH, DATEDIFF(MONT...

Show Detail

How to Convert SQL Server Query to MySQL Query

I'm trying to convert this SQL Server query to MySQL query how can i do that? Fallowing is my SQL server query. I need to convert this query to execute in MySQL. EpfNO is the Primary key and IsVali...

Show Detail

Converting Postgres query to SQL Server

Can you please help me with how I can adjust the query that I can run in SQL Server instead of Postgres? WITH j AS ( SELECT date_trunc( 'month', occurred_at::date ) AS month,

Show Detail

SQL SERVER QUERY to MYSQL QUERY

I am trying to convert this MSSQL QUERY to MYSQL Query looks like this select tu.FirstName+' '+tu.LastName as name,tg.Name as game_name,tg.Status,tg.UserId,tg.gameid from tblUsers tu inner ...

Show Detail

convert mysql query to sql server query

I want to convert below mysql query to sql query.I want to use If condition in sql server SELECT foodName, IF( foodPrice>2000, 'Expensive', 'Cheap') as fpDesc, discountPercent FROM restaurant.f...

Show Detail

MySQL query to SQL Server query

I defined sql query and it runs with no problem on MySQL (I am using MySQL) , but when I am trying to execute it on client site (they uses SQL Server) I am getting "Error: Incorrect syntax near 'si...

Show Detail

SQL Server Query to MySQL query conversion

I am doing query conversion from SQL Server to MySQL. So can anyone suggest a website which provides the different keywords that will do the same operation in SQL Server and MySQL respectively? For

Show Detail