簡體   English   中英

如何在 MySQL 數據庫中的 select 子查詢中 select 多列?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM