我正在尝试使用此查询,我需要在比较之前连接一个字符串以获得正确的结果。查询正在运行,但未找到任何结果。我相信问题出在我尝试比较WHERE
子句中的“myname”时。知道什么是正确的查询吗?
SELECT *
FROM (SELECT CONCAT('tm_',name) AS myname FROM room) room, users
WHERE user_name = myname;
为什么不
SELECT * FROM users,room where user_name=concat('tm_',name);
?
试试这个
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"