[英]Select rows in a table where id is equals to another id in another table
I would like to select a certain row in my getadvocacy table where id is the id in another table called swimsuit. 我想在我的getadvocacy表中选择某一行,其中id是另一个表中的id,称为Swimsuit。
swimsuit table 泳衣桌
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
Now, I want to select from getadvocacy but only 1 and 3 because it is the data on swimsuit. 现在,我要从getadvocacy中进行选择,但只能选择1和3,因为它是泳衣上的数据。
Expected Output 预期产量
id | all_scores | average_score
1 | 70,70,70 | 70
3 | 70,70,70 | 70
I tried this but it has different output. 我试过了,但是它有不同的输出。
select getadvocacy.id, all_scores, average_score from getadvocacy WHERE getadvocacy.id IN (select id from swimsuit)
If the id (primary key) is same for table then you can use join on Id 如果表的ID(主键)相同,则可以在ID上使用join
select * from table1
JOIN table2
on table1.id = table2.id
Use this 用这个
select * from swimsuit JOIN getadvocacy ON swimsuit.id= getadvocacy.id;
Result of query is 查询结果是
1 abc 90 1 50,60,70 70
3 def 99 3 60,70,70 70
in standard sql you have to do: 在标准sql中,您必须执行以下操作:
select *
from getadvocacy
where
id in (select st.id from "swimsuit table" as st)
Simplest and easier to understand: Just by reading between the lines, you will understand how this snippet works 最简单易懂:只需在两行之间阅读,您就会了解此代码段的工作方式
SELECT getadvocacy.* , swimsuittable.*
FROM getadvocacy, swimsuittable
WHERE getadvocacy.id = swimsuittable.id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.