我有下面提到的两张table。
user table
id | username | password | status |
1 | Prajna |***** | active |
2 | Akshata |***** | active |
3 | Sanjana |***** | inactive |
test table
id | project_name | created_by (user id) | edited_by (user id) |
1 | Test | 1 | 2 |
2 | Trial | 1 | 1 |
3 | Pro1 | 2 | 2 |
我正在尝试下面的查询。
select project_name, user.username from test join user on user.id=test.created_by where user.status='active';
我想要的结果如下
我想检索的结果如下我怎么能检索?
project_name | username(created by) | username (edited by) |
Test | Prajna | Akshata |
Trial | Prajna | Prajna |
Pro1 | Akshata | Akshata |
3条答案
按热度按时间qnakjoqk1#
你需要
sub-query
并使用join
```select project_name,created_by,edited_by from
(
select u.id,project_name, u.username as created_by from user u left join test t1 on
u.id= t1.created_by
where user.status='active'
) Table1
inner join
(
) table2 on Table1.project_name=table2.project_name
q3qa4bjr2#
ps:你在这里有一个错误user.id=test=created\u by。
ou6hu8tu3#
试试这个代码。
db<>在这里摆弄