这也被认为是子查询吗?
我知道以下查询是如何工作的,我只是对术语感到困惑。
每个查询都以强制 FROM 子句开始,并且必须以 SELECT 或 GROUP 子句结束。在两个子句之间,我们可以放置任意数量的可选 FROM...LET...WHERE 子句。子查询只是查询中的查询,这意味着它也具有相同的结构:
var result = from p1 in artists
from p3 in (from p2 in p1.albums
select new { ID = p2.id, Title = p2.title })
select p3;
但与上面示例中的子查询不同,以下子查询( from p2 in Artist.Albums
)不以它有自己的 SELECT/GROUP 子句,因此其结构在某种意义上有所不同,它以 FROM 子句开头,但不以 SELECT/GROUP 子句结尾。所以我的问题是术语子查询是否也适用于from p2 in Artist.Albums
,即使它的结构有点不同?
var result1 = from p1 in artists
from p2 in p1.Albums
select new { Artist_id = p1.id, Album_id = p2.id };
谢谢
I know how the following queries work, I'm just confused about the terminology.
Each query begins with mandatory FROM clause and must end with either SELECT or GROUP clause. Between the two clauses we can put any number of optional FROM...LET...WHERE clauses. Subquery is simply a query within a query, which means it too has the same structure:
var result = from p1 in artists
from p3 in (from p2 in p1.albums
select new { ID = p2.id, Title = p2.title })
select p3;
But unlike the subquery in the above example, the following subquery ( from p2 in artist.Albums
) doesn't end with its very own SELECT/GROUP clause, so its structure is different in a sense that it begins with a FROM clause, but doesn't end with SELECT/GROUP clause. So my question is whether the term subquery also applies to from p2 in artist.Albums
, even though its structure is a bit different?
var result1 = from p1 in artists
from p2 in p1.Albums
select new { Artist_id = p1.id, Album_id = p2.id };
thank you
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,在底部您正在执行隐式连接,而不是子查询。连接是同时查询两个表(在同一个查询中)的地方。
No, at the bottom you're doing an implicit join, not a subquery. A join is where you query both tables at the same time (in the same query).
在第二个查询
result1
中,没有子查询,只是一个带有两个from
子句的查询。在幕后,以这种方式使用两个
from
子句将被转换为SelectMany
操作:In your second query,
result1
, there is no subquery, just a query with twofrom
clauses.Behind the scenes, using two
from
clauses in this way will be translated into aSelectMany
operation: