<bdo id='Ii2E9'></bdo><ul id='Ii2E9'></ul>

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

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

  • <legend id='Ii2E9'><style id='Ii2E9'><dir id='Ii2E9'><q id='Ii2E9'></q></dir></style></legend>

      <tfoot id='Ii2E9'></tfoot>
      1. MySQL内连接查询多表

        MySQL Inner Join Query Multiple Tables(MySQL内连接查询多表)
        <i id='LTfbn'><tr id='LTfbn'><dt id='LTfbn'><q id='LTfbn'><span id='LTfbn'><b id='LTfbn'><form id='LTfbn'><ins id='LTfbn'></ins><ul id='LTfbn'></ul><sub id='LTfbn'></sub></form><legend id='LTfbn'></legend><bdo id='LTfbn'><pre id='LTfbn'><center id='LTfbn'></center></pre></bdo></b><th id='LTfbn'></th></span></q></dt></tr></i><div id='LTfbn'><tfoot id='LTfbn'></tfoot><dl id='LTfbn'><fieldset id='LTfbn'></fieldset></dl></div>
        • <small id='LTfbn'></small><noframes id='LTfbn'>

          • <tfoot id='LTfbn'></tfoot>
            1. <legend id='LTfbn'><style id='LTfbn'><dir id='LTfbn'><q id='LTfbn'></q></dir></style></legend>
                <bdo id='LTfbn'></bdo><ul id='LTfbn'></ul>

                  <tbody id='LTfbn'></tbody>

                  本文介绍了MySQL内连接查询多表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试连接一些表格,布局示例如下:

                  I am trying to join up a few tables and examples of the layouts are below:

                  订单

                  user_id=7 pricing id=37
                  

                  products_pricing

                  products_pricing

                  id=37 product_id=33
                  

                  产品

                  id=33 name=test product
                  

                  SQL

                  SELECT *
                  FROM orders
                    INNER JOIN products_pricing
                      ON orders.pricing_id = products_pricing.id
                    INNER JOIN products
                      ON products_pricing.product_id = products.id
                  WHERE orders.user_id = '7' ");
                  

                  列表

                  id=233 user_id=7 url=test.com
                  

                  使用此 SQL,我得到一个输出,其中包含 user_id 为 7 的所有产品,它将在 while 循环中列出每个产品名称.但是,当我为一个名为列表的表添加另一个 INNER JOIN 时,该表有一个 user_id 列,我需要为匹配的每一行获取一个 url,以便我可以将产品名称与 url 超链接,我也得到列表表中包含的所有内容作为上面的工作内容.我要么做错了,要么错过了一些东西.我花了几个小时试图弄清楚,但一直得到相同的结果.谁能帮帮我?

                  With this SQL i get an output giving me all the products from the user_id of 7 and it will list each products name in a while loop. However when I add another INNER JOIN for a table called listings, which has a user_id column and I need to grab a url for each row that matches so I can hyperlink the product names with the url I get everything contained in the listings table as well as the working stuff above. I'm either doing it very wrong or am missing something. I've spent a few hours trying to figure it out but keep getting the same result. Can anyone help me out?

                  推荐答案

                  试试这个:

                  SELECT 
                    p.id,
                    p.name,
                    l.url,
                    o.user_id,
                    o.pricing_id
                  FROM orders AS o
                  INNER JOIN products_pricing AS pp ON o.pricing_id  = pp.id
                  INNER JOIN products         AS  p ON pp.product_id = p.id
                  INNER JOIN listings         AS  l ON l.user_id = o.user_id
                  WHERE o.user_id ='7' 
                    AND l.id = 233 
                    AND l.url = 'test.com';
                  

                  SQL Fiddle 演示

                  对于您在问题中发布的示例数据,这将为您提供:

                  SQL Fiddle Demo

                  For the sample data you posted in your question, this will give you:

                  | ID |        NAME |      URL | USER_ID | PRICING_ID |
                  ------------------------------------------------------
                  | 33 | testproduct | test.com |       7 |         37 |
                  

                  这篇关于MySQL内连接查询多表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                1. <legend id='u4W5E'><style id='u4W5E'><dir id='u4W5E'><q id='u4W5E'></q></dir></style></legend>
                  <tfoot id='u4W5E'></tfoot>
                  • <small id='u4W5E'></small><noframes id='u4W5E'>

                      <tbody id='u4W5E'></tbody>
                      <bdo id='u4W5E'></bdo><ul id='u4W5E'></ul>

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