简体   繁体   中英

How to use a subquery/join with three tables in mysql?

testplan

  1. id
  2. testplan_id
  3. tcversion_id
  4. platform_id

executions

1. id
2. build_id
3. testplan_id
4. tcversion_id
5. platform_id
6. status
7. execution_ts
8. tester_id

builds

1. id
2. testplan_id
3. name
4. active

I have three tables as shown above. testplan table stores all the cases executions tables store execution related data builds table stores builds related data

I want to retrive data from these table in such a way that it should display all rows from testplan table, for each row if any execution is there from execution's table and only the build names from builds tables.

I used following query

SELECT
tptcv.id,
tptcv.testplan_id,
e.tcversion_id,
tptcv.platform_id,
tptcv.creation_ts,
b.name AS Build_name,
e.status AS status,
e.execution_ts,
e.tester_id
from testplan tptcv
inner join executions e on tptcv.tcversion_id=e.tcversion_id and     tptcv.platform_id=e.platform_id and tptcv.testplan_id=e.testplan_id
inner join builds b on tptcv.testplan_id=b.testplan_id
WHERE
b.active=1 

enter code here

This query doesn't giving me the expected result as enter code here per the count needed compare to rows in testplan table.

I will appreciate if some help me in this case.

Thanks in advance.

删除WHERE b.active = 1并检查是否获得预期的答案(因为构建表没有名为active的列)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM