我想在我的getadvocacy表中选择某一行,其中id是另一个名为泳装的表中的id。
泳装表
id | name | average
1 | Abc | 90
3 | Def | 99
getadvocacy
id | all_scores | average_score
1 | 70,70,70 | 70
2 | 70,70,70 | 70
3 | 70,70,70 | 70
现在,我想从getadvocacy中选择但只有1和3,因为它是泳装上的数据。
预期输出
id | all_scores | average_score
1 | 70,70,70 | 70
3 | 70,70,70 | 70
我尝试了这个,但它有不同的输出。
select getadvocacy.id, all_scores, average_score from getadvocacy WHERE getadvocacy.id IN (select id from swimsuit)
答案 0 :(得分:1)
如果表的id(主键)相同,则可以使用Id上的连接
select * from table1
JOIN table2
on table1.id = table2.id
使用此
select * from swimsuit JOIN getadvocacy ON swimsuit.id= getadvocacy.id;
查询结果是
1 abc 90 1 50,60,70 70
3 def 99 3 60,70,70 70
答案 1 :(得分:0)
在标准sql中你必须这样做:
select *
from getadvocacy
where
id in (select st.id from "swimsuit table" as st)
答案 2 :(得分:0)
最简单易懂:
SELECT getadvocacy.* , swimsuittable.*
FROM getadvocacy, swimsuittable
WHERE getadvocacy.id = swimsuittable.id