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

    <tfoot id='YPNtH'></tfoot>

  • <legend id='YPNtH'><style id='YPNtH'><dir id='YPNtH'><q id='YPNtH'></q></dir></style></legend>
      <bdo id='YPNtH'></bdo><ul id='YPNtH'></ul>

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

      1. 使用的 SELECT 语句具有不同的列数(REDUX !!)

        时间:2023-06-01

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

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

              <tfoot id='Bvxxp'></tfoot>
                    <tbody id='Bvxxp'></tbody>
                  本文介绍了使用的 SELECT 语句具有不同的列数(REDUX !!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  还有一个与此类似的问题,但它似乎没有回答我的问题.

                  There's another question out there similar to this, but it didn't seem to answer my question.

                  我的问题是:为什么我会返回这个错误 ERROR 1222 (21000): The used SELECT statements have a different number of columns 来自以下 SQL

                  My question is this: why am I getting back this error ERROR 1222 (21000): The used SELECT statements have a different number of columns from the following SQL

                  SELECT * FROM friends
                  LEFT JOIN users AS u1 ON users.uid = friends.fid1
                  LEFT JOIN users AS u2 ON users.uid = friends.fid2
                  WHERE (friends.fid1 = 1) AND (friends.fid2 > 1)
                  UNION SELECT fid2 FROM friends
                  WHERE (friends.fid2  = 1) AND (friends.fid1 < 1)
                  ORDER BY RAND()
                  LIMIT 6;
                  

                  这是用户:

                  +------------+---------------+------+-----+---------+----------------+
                  | Field      | Type          | Null | Key | Default | Extra          |
                  +------------+---------------+------+-----+---------+----------------+
                  | uid        | int(11)       | NO   | PRI | NULL    | auto_increment |
                  | first_name | varchar(50)   | NO   |     | NULL    |                |
                  | last_name  | varchar(50)   | NO   |     | NULL    |                |
                  | email      | varchar(128)  | NO   | UNI | NULL    |                |
                  | mid        | varchar(40)   | NO   |     | NULL    |                |
                  | active     | enum('N','Y') | NO   |     | NULL    |                |
                  | password   | varchar(64)   | NO   |     | NULL    |                |
                  | sex        | enum('M','F') | YES  |     | NULL    |                |
                  | created    | datetime      | YES  |     | NULL    |                |
                  | last_login | datetime      | YES  |     | NULL    |                |
                  | pro        | enum('N','Y') | NO   |     | NULL    |                |
                  +------------+---------------+------+-----+---------+----------------+
                  

                  这里是朋友:

                  +---------------+--------------------------------------+------+-----+---------+----------------+
                  | Field         | Type                                 | Null | Key | Default | Extra          |
                  +---------------+--------------------------------------+------+-----+---------+----------------+
                  | friendship_id | int(11)                              | NO   | MUL | NULL    | auto_increment |
                  | fid1          | int(11)                              | NO   | PRI | NULL    |                |
                  | fid2          | int(11)                              | NO   | PRI | NULL    |                |
                  | status        | enum('pending','accepted','ignored') | NO   |     | NULL    |                |
                  +---------------+--------------------------------------+------+-----+---------+----------------+
                  

                  如果您也想对这里发生的任何疯狂事情提供任何反馈,请随时提出.我会吃我的肿块.

                  If you want to give any feedback on anything crazy you see going on here, as well, please feel free to do so. I'll take my lumps.

                  推荐答案

                  UNION(UNIONUNION ALL)要求所有被 UNION 连接的查询:

                  UNIONs (UNION and UNION ALL) require that all the queries being UNION'd have:

                  1. SELECT 子句中的列数相同
                  2. 列数据类型必须在每个位置匹配

                  您的查询有:

                  SELECT f.*, u1.*, u2.* ...
                  UNION 
                  SELECT fid2 FROM friends
                  

                  我最简单的重写是:

                     SELECT f.*, u.*
                       FROM FRIENDS AS f
                       JOIN USERS AS u ON u.uid = f.fid2
                      WHERE f.fid1 = 1 
                        AND f.fid2 > 1
                  UNION 
                     SELECT f.*, u.*
                       FROM FRIENDS AS f
                       JOIN USERS AS u ON u.uid = f.fid1
                      WHERE f.fid2  = 1 
                        AND f.fid1 < 1
                  ORDER BY RAND()
                  LIMIT 6;
                  

                  您已 LEFT JOIN 到 USERS 表两次,但似乎没有使用这些信息.

                  You've LEFT JOIN'd to the USERS table twice, but don't appear to be using the information.

                  这篇关于使用的 SELECT 语句具有不同的列数(REDUX !!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何在mysql中启用INNODB 下一篇:MySQL日期格式

                  相关文章

                  <tfoot id='eKivv'></tfoot>

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

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

                    • <bdo id='eKivv'></bdo><ul id='eKivv'></ul>
                      <legend id='eKivv'><style id='eKivv'><dir id='eKivv'><q id='eKivv'></q></dir></style></legend>