<bdo id='zQLoH'></bdo><ul id='zQLoH'></ul>
    <i id='zQLoH'><tr id='zQLoH'><dt id='zQLoH'><q id='zQLoH'><span id='zQLoH'><b id='zQLoH'><form id='zQLoH'><ins id='zQLoH'></ins><ul id='zQLoH'></ul><sub id='zQLoH'></sub></form><legend id='zQLoH'></legend><bdo id='zQLoH'><pre id='zQLoH'><center id='zQLoH'></center></pre></bdo></b><th id='zQLoH'></th></span></q></dt></tr></i><div id='zQLoH'><tfoot id='zQLoH'></tfoot><dl id='zQLoH'><fieldset id='zQLoH'></fieldset></dl></div>
        <tfoot id='zQLoH'></tfoot>
      1. <legend id='zQLoH'><style id='zQLoH'><dir id='zQLoH'><q id='zQLoH'></q></dir></style></legend>

        <small id='zQLoH'></small><noframes id='zQLoH'>

      2. 在 Select 中合并两个表 (SQL Server 2008)

        时间:2023-10-08
          <tbody id='IFYeO'></tbody>
          <bdo id='IFYeO'></bdo><ul id='IFYeO'></ul>
        • <legend id='IFYeO'><style id='IFYeO'><dir id='IFYeO'><q id='IFYeO'></q></dir></style></legend>

            • <tfoot id='IFYeO'></tfoot>

                1. <small id='IFYeO'></small><noframes id='IFYeO'>

                  <i id='IFYeO'><tr id='IFYeO'><dt id='IFYeO'><q id='IFYeO'><span id='IFYeO'><b id='IFYeO'><form id='IFYeO'><ins id='IFYeO'></ins><ul id='IFYeO'></ul><sub id='IFYeO'></sub></form><legend id='IFYeO'></legend><bdo id='IFYeO'><pre id='IFYeO'><center id='IFYeO'></center></pre></bdo></b><th id='IFYeO'></th></span></q></dt></tr></i><div id='IFYeO'><tfoot id='IFYeO'></tfoot><dl id='IFYeO'><fieldset id='IFYeO'></fieldset></dl></div>
                  本文介绍了在 Select 中合并两个表 (SQL Server 2008)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果我有两个表,例如:

                  If I have two tables, like this for example:

                  表 1(产品)

                  id
                  name
                  price
                  agentid
                  

                  表2(代理)

                  userid
                  name
                  email
                  

                  如何从包含代理名称和电子邮件的产品中获取结果集,这意味着 products.agentid = agent.userid?

                  How do I get a result set from products that include the agents name and email, meaning that products.agentid = agent.userid?

                  我如何加入例如 SELECT WHERE price <100?

                  推荐答案

                  编辑以支持价格过滤

                  您可以使用 INNER JOIN 子句来连接这些表.它是这样完成的:

                  You can use the INNER JOIN clause to join those tables. It is done this way:

                  select p.id, p.name as ProductName, a.userid, a.name as AgentName
                  from products p
                  inner join agents a on a.userid = p.agentid
                  where p.price < 100
                  

                  另一种方法是通过 WHERE 子句:

                  Another way to do this is by a WHERE clause:

                  select p.id, p.name as ProductName, a.userid, a.name as AgentName
                  from products p, agents a
                  where a.userid = p.agentid and p.price < 100
                  

                  请注意,在第二种情况下,您正在对两个表中的所有行进行自然乘积,然后过滤结果.在第一种情况下,您在加入同一步骤时直接过滤结果.DBMS 将了解您的意图(无论您选择以何种方式解决此问题)并以最快的方式处理.

                  Note in the second case you are making a natural product of all rows from both tables and then filtering the result. In the first case you are directly filtering the result while joining in the same step. The DBMS will understand your intentions (regardless of the way you choose to solve this) and handle it in the fastest way.

                  这篇关于在 Select 中合并两个表 (SQL Server 2008)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:选择所有列对性能不利吗? 下一篇:添加“字段"从 UNION 到 SQL 结果的表名?

                  相关文章

                  <i id='CV2lO'><tr id='CV2lO'><dt id='CV2lO'><q id='CV2lO'><span id='CV2lO'><b id='CV2lO'><form id='CV2lO'><ins id='CV2lO'></ins><ul id='CV2lO'></ul><sub id='CV2lO'></sub></form><legend id='CV2lO'></legend><bdo id='CV2lO'><pre id='CV2lO'><center id='CV2lO'></center></pre></bdo></b><th id='CV2lO'></th></span></q></dt></tr></i><div id='CV2lO'><tfoot id='CV2lO'></tfoot><dl id='CV2lO'><fieldset id='CV2lO'></fieldset></dl></div>

                  • <bdo id='CV2lO'></bdo><ul id='CV2lO'></ul>

                    1. <legend id='CV2lO'><style id='CV2lO'><dir id='CV2lO'><q id='CV2lO'></q></dir></style></legend>
                    2. <tfoot id='CV2lO'></tfoot>

                      <small id='CV2lO'></small><noframes id='CV2lO'>