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