简体   繁体   English

使用一行从另一张表中选择两行

[英]Selecting two rows from another table using one row

table1 表格1

[      id      -      title      -      content      -      class      ]
[      1       -        2        -         3         -        1        ]
[      1       -        2        -         3         -        2        ]

table2 表2

[      id      -       data      -    permission     -      class      ]
[      a       -        b        -         c         -        1        ]
[      a       -        b        -         c         -        2        ]

How can i select the column data from table2 while selecting all table1 在选择所有table1时如何从table2中选择列data

my query is SELECT title, content FROM table1 WHERE class = 1 我的查询是SELECT title, content FROM table1 WHERE class = 1

How can i select column data and permission in this query? 如何在此查询中选择列datapermission

Assuming the relationship is based on class: 假设关系基于类:

select table1.*,table2.data, table2.permission
from table1 
join table2 on table1.class = table2.class 
where table1.class = 1

You can do this with a simple JOIN : 您可以使用简单的JOIN来做到这一点:

Select  T1.*, T2.Data, T2.Permission
From    Table1  T1
Join    Table2  T2  On  T1.Class = T2.Class
Where   T1.Class = 1
select t1.title, t1.content, t2.data from table1 t1 join table2 t2
on t1.class=t2.class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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