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

        Combine Two Tables in Select (SQL Server 2008)(在 Select 中合并两个表 (SQL Server 2008))
          <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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Building a comma separated list?(建立一个逗号分隔的列表?)
                  Errors in SQL Server while importing CSV file despite varchar(MAX) being used for each column(尽管每列都使用了 varchar(MAX),但在导入 CSV 文件时 SQL Server 中出现错误)
                  How can I import an Excel file into SQL Server?(如何将 Excel 文件导入 SQL Server?)
                  Export table to file with column headers (column names) using the bcp utility and SQL Server 2008(使用 bcp 实用程序和 SQL Server 2008 将表导出到带有列标题(列名称)的文件)
                  Concat field value to string in SQL Server(将字段值连接到 SQL Server 中的字符串)
                  SQL Server Bulk insert of CSV file with inconsistent quotes(SQL Server 批量插入带有不一致引号的 CSV 文件)
                    <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>

                      <tbody id='CV2lO'></tbody>
                      <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'>