[英]How to select multiple columns in a select sub-query in MySQL database?
我正在尝试获取另一个表的一行作为 SELECT 查询的子查询。
SELECT g.ip, g.version, t.testid, t.status, m.rundate, t.runid , (select * from B where runid=t.runid and testid=t.testid)
FROM Tests t, Master m, Env g
WHERE t.runid=m.runid
AND t.runid=g.runid
AND g.version = "1.2.3"
AND t.testid like "%test_name%"
AND g.ip in ("198.18.111.222")
order by m.rundate desc;
如何做到这一点? 谢谢!
试试这个:
SELECT g.ip, g.version, t.testid, t.status, m.rundate, t.runid , c.* from B c
Join Tests t on t.runid =t.testid
join Master m on t.runid=m.runid
join Env g on t.runid=g.runid
WHERE g.version = "1.2.3" AND t.testid like "%test_name%"
AND g.ip in ("198.18.111.222")
order by m.rundate desc;
在第 2 行,如果 B 表中有任何 id 与 Tests 中的 id 匹配,请替换 t.runid = t.testid(假设如果 B 表中有与测试表 testid 相关的 runid,则替换为 c.runid = t。 testid)到B表和tests表满足匹配ID(PK和FK)场景的需求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.