这也被认为是子查询吗?

发布于 2024-12-06 01:35:18 字数 740 浏览 0 评论 0原文

我知道以下查询是如何工作的,我只是对术语感到困惑。

每个查询都以强制 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

腻橙味 2024-12-13 01:35:18

不,在底部您正在执行隐式连接,而不是子查询。连接是同时查询两个表(在同一个查询中)的地方。

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).

哭了丶谁疼 2024-12-13 01:35:18

在第二个查询 result1 中,没有子查询,只是一个带有两个 from 子句的查询。

在幕后,以这种方式使用两个 from 子句将被转换为 SelectMany 操作:

artists.SelectMany( p1      => p1.albums
                   ,(p1,p2) => new { Artist_id = p1.id, Album_id = p2.id })

In your second query, result1, there is no subquery, just a query with two from clauses.

Behind the scenes, using two from clauses in this way will be translated into a SelectMany operation:

artists.SelectMany( p1      => p1.albums
                   ,(p1,p2) => new { Artist_id = p1.id, Album_id = p2.id })
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文