0

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 join tblGame tg on  
tu.UserId=tg.UserId where tg.Name LIKE @Name + '%' 

the same query doesnt return any records when i run it on MYSQL, what is the issue ? It works good on SQL server

2 Answers 2

1
SELECT CONCAT_WS(' ', tu.FirstName, tu.LastName) AS name, tg.Name AS game_name,tg.Status,tg.UserId,tg.gameid
FROM tblUsers tu    
INNER JOIN tblGame tg ON tu.UserId=tg.UserId
WHERE tg.Name LIKE CONCAT(tu.FirstName, ' ', tu.LastName, '%')

Notes:

  • it's case insensitive, I've used upper case just for readability
  • I've intentionally used both concat and concat_ws to show them as options
Sign up to request clarification or add additional context in comments.

Comments

0
select tu.FirstName+' '+tu.LastName as name,tg.Name as
game_name,tg.Status,tg.UserId,tg.gameid from tblUsers tu
inner join tblGame tg on
tu.UserId=tg.UserId where tg.Name LIKE @Name + '%' 

select concat(tu.firstName,' ',tu.lastName) as name, ,tg.Name as
game_name,tg.Status,tg.UserId,tg.gameid from tblUsers as tu
inner join tblGame as tg on
tu.UserId=tg.UserId where tg.Name LIKE concat(@Name,'%');

Note that, there is not (for example) field1+' '+field2, There is concat, concat_ws, and group_concat, read about it, it's super useful.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.