0

我正在尝试使用此查询,我需要在比较之前连接一个字符串以获得正确的结果。查询正在运行,但未找到任何结果。我相信问题出在我尝试比较WHERE子句中的“myname”时。知道什么是正确的查询吗?

SELECT * 
FROM (SELECT CONCAT('tm_',name) AS myname FROM room) room, users
WHERE user_name = myname;
4

2 回答 2

1

为什么不

SELECT * FROM users,room where user_name=concat('tm_',name);

?

于 2012-09-26T13:03:31.527 回答
0

试试这个

SELECT *
FROM 
(
   SELECT CONCAT('tm_',name) AS myname 
   FROM room
) t
WHERE user_name = myname

可能你需要像这样JOIN的另一个表users

SELECT *
FROM 
(
   SELECT CONCAT('tm_',name) AS myname 
   FROM room
) t
INNER JOIN users u ON ... --some join condition
WHERE user_name = myname

或者:

SELECT *
FROM 
(
   SELECT CONCAT('tm_',name) AS myname 
   FROM room
) t, users
WHERE t.user_name = myname"
于 2012-09-26T13:02:14.513 回答