<legend id='V2sO1'><style id='V2sO1'><dir id='V2sO1'><q id='V2sO1'></q></dir></style></legend>
          <bdo id='V2sO1'></bdo><ul id='V2sO1'></ul>
      1. <small id='V2sO1'></small><noframes id='V2sO1'>

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

        1052:字段列表中的列“id"不明确

        时间:2023-08-19
            <bdo id='VeCKi'></bdo><ul id='VeCKi'></ul>
              <tbody id='VeCKi'></tbody>

          • <tfoot id='VeCKi'></tfoot>
          • <small id='VeCKi'></small><noframes id='VeCKi'>

                  <legend id='VeCKi'><style id='VeCKi'><dir id='VeCKi'><q id='VeCKi'></q></dir></style></legend>
                  <i id='VeCKi'><tr id='VeCKi'><dt id='VeCKi'><q id='VeCKi'><span id='VeCKi'><b id='VeCKi'><form id='VeCKi'><ins id='VeCKi'></ins><ul id='VeCKi'></ul><sub id='VeCKi'></sub></form><legend id='VeCKi'></legend><bdo id='VeCKi'><pre id='VeCKi'><center id='VeCKi'></center></pre></bdo></b><th id='VeCKi'></th></span></q></dt></tr></i><div id='VeCKi'><tfoot id='VeCKi'></tfoot><dl id='VeCKi'><fieldset id='VeCKi'></fieldset></dl></div>
                  本文介绍了1052:字段列表中的列“id"不明确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我有两张桌子.tbl_namestbl_section 都包含 id 字段.我如何选择 id 字段,因为我总是收到此错误:

                  1052: 字段列表中的列 'id' 不明确

                  这是我的查询:

                  SELECT id, name, section从 tbl_names, tbl_section哪里 tbl_names.id = tbl_section.id

                  我可以选择所有字段并避免错误.但这会浪费性能.我该怎么办?

                  解决方案

                  SQL 支持通过在引用前加上全表名来限定列:

                  SELECT tbl_names.id, tbl_section.id, name, section从 tbl_names在 tbl_section.id = tbl_names.id 上加入 tbl_section

                  ...或表别名:

                  SELECT n.id, s.id, n.name, s.sectionFROM tbl_names n加入 tbl_section s ON s.id = n.id

                  表别名是推荐的方法——为什么要输入更多的内容?

                  为什么这些查询看起来不同?

                  其次,我的回答使用 ANSI-92 JOIN 语法(你的是 ANSI-89).虽然它们执行相同的操作,但 ANSI-89 语法不支持外部连接(RIGHT、LEFT、FULL).ANSI-89 语法应该被视为已弃用,SO 上有很多人不会投票支持 ANSI-89 语法来加强这一点.如需更多信息,请参阅此问题.>

                  I have 2 tables. tbl_names and tbl_section which has both the id field in them. How do I go about selecting the id field, because I always get this error:

                  1052: Column 'id' in field list is ambiguous
                  

                  Here's my query:

                  SELECT id, name, section
                    FROM tbl_names, tbl_section 
                   WHERE tbl_names.id = tbl_section.id
                  

                  I could just select all the fields and avoid the error. But that would be a waste in performance. What should I do?

                  解决方案

                  SQL supports qualifying a column by prefixing the reference with either the full table name:

                  SELECT tbl_names.id, tbl_section.id, name, section
                    FROM tbl_names
                    JOIN tbl_section ON tbl_section.id = tbl_names.id 
                  

                  ...or a table alias:

                  SELECT n.id, s.id, n.name, s.section
                    FROM tbl_names n
                    JOIN tbl_section s ON s.id = n.id 
                  

                  The table alias is the recommended approach -- why type more than you have to?

                  Why Do These Queries Look Different?

                  Secondly, my answers use ANSI-92 JOIN syntax (yours is ANSI-89). While they perform the same, ANSI-89 syntax does not support OUTER joins (RIGHT, LEFT, FULL). ANSI-89 syntax should be considered deprecated, there are many on SO who will not vote for ANSI-89 syntax to reinforce that. For more information, see this question.

                  这篇关于1052:字段列表中的列“id"不明确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何从MySQL中的多个表中删除? 下一篇:如何更改 max_allowed_pa​​cket 大小

                  相关文章

                  最新文章

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

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

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