这和MYSQL查询中的JOIN一样吗?

发布于 2024-12-05 15:57:11 字数 355 浏览 1 评论 0原文

这是我的疑问:

这看起来有效吗?使用 JOIN 有优势吗?或者说这也是一样的吗?

$query_Recordset2 = 
"SELECT cute_news.category, cute_news.id, cute_story.short, cute_story.post_id, cute_news.date, cute_news.url, cute_news.title 
FROM cute_news, cute_story 
WHERE cute_news.id = cute_story.post_id AND category LIKE '10%' 
ORDER BY date DESC LIMIT 0,35";

Here is my query:

Does this look efficient? Is there an advantage of using JOIN? Or is this the same?

$query_Recordset2 = 
"SELECT cute_news.category, cute_news.id, cute_story.short, cute_story.post_id, cute_news.date, cute_news.url, cute_news.title 
FROM cute_news, cute_story 
WHERE cute_news.id = cute_story.post_id AND category LIKE '10%' 
ORDER BY date DESC LIMIT 0,35";

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

零時差 2024-12-12 15:57:11

这个问题可能与那个问题重复< /a>.

隐式 JOIN 不包含意图,因此可读性较差。

您的查询将产生与以下完全相同的结果:

SELECT cute_news.category, cute_news.id, cute_story.short, cute_story.post_id, cute_news.date, cute_news.url, cute_news.title 
FROM cute_news
 INNER JOIN cute_story ON cute_story.post = cute_news.id
WHERE category LIKE '10%' 
ORDER BY date DESC LIMIT 0,35

但后一个查询的可读性要高得多,因为您将 JOIN 谓词与过滤器分开并表达了查询背后的逻辑。

This question might be a duplicate of that one.

Implicit JOINs do not carry the intent, and are thus less readable.

Your query will lead to strictly same results as:

SELECT cute_news.category, cute_news.id, cute_story.short, cute_story.post_id, cute_news.date, cute_news.url, cute_news.title 
FROM cute_news
 INNER JOIN cute_story ON cute_story.post = cute_news.id
WHERE category LIKE '10%' 
ORDER BY date DESC LIMIT 0,35

but the latter query is far more readable because you separate JOIN predicates from filters and express the logic behind the query.

沙与沫 2024-12-12 15:57:11

“隐式连接表示法”只是列出要连接的表(在 SELECT 语句的 FROM 子句中),并使用逗号分隔它们。因此,它指定了交叉连接,并且 WHERE 子句可以应用额外的过滤谓词(其功能与显式表示法中的连接谓词相当)

因此,它指定了交叉连接,并且 WHERE 子句可以应用来自 wikipedia

换句话说,都是一样的

The "implicit join notation" simply lists the tables for joining (in the FROM clause of the SELECT statement), using commas to separate them. Thus, it specifies a cross join, and the WHERE clause may apply additional filter-predicates (which function comparably to the join-predicates in the explicit notation)

from wikipedia

In other words it's the same

一片旧的回忆 2024-12-12 15:57:11

如果您的意思是 FROM 子句具有多个以逗号分隔的表,那么是的,它与 INNER JOIN 基本相同。

然而,这是旧语法;优先使用INNER JOIN,这是更标准的。

此外,旧语法的问题在于,通过将连接字段与 WHERE 子句的其余部分组合起来,可能会使查询难以阅读,并且在某些情况下会导致解析器承担额外的工作。最好在每个 JOINON 子句中明确说明关系。

If you mean the FROM clause having multiple tables, comma-separated, then yes, it is basically the same as an INNER JOIN.

However, this is old syntax; it is preferred to use INNER JOIN, which is more standard.

In addition, the problem with the old syntax is that by combining the joining fields with the rest of the WHERE clause, it can make the query hard to read, and in some cases cause extra work for the parser. It is much better to explicitly state the relationships in the ON clause for each JOIN.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文