mysql子查询错误[21000] [1241]操作数应包含1列

时间:2019-02-05 06:51:50

标签: mysql sql subquery

我有一个叫做交易对手的表格。 我要在这张桌子上查询 像这样:

SELECT (`name`, `mark`, `parent`, `description`) AS table_1 FROM (SELECT 
`name`, `mark`, `parent`, `description` FROM counterparty) AS table_2 WHERE 
(table_1.mark <> table_2.parent);

但是下面的错误显示:

[21000] [1241]操作数应包含1列

我该如何解决?

2 个答案:

答案 0 :(得分:0)

您可以尝试以下操作-使用SELF JOIN

SELECT table_1 .`name`, table_1.`mark`, table_1.`parent`, table_1 .`description` 
FROM counterparty table_1 inner join counterparty table_2 
table_1.mark <> table_2.parent;

答案 1 :(得分:0)

您编写子查询时出错,可以通过使用join尝试如下所示

SELECT  t1.* from table_1 t1    
 join  (SELECT 
`name`, `mark`, `parent`, `description` FROM counterparty
       ) AS table_2 t2 on  t1.mark!=t2.mark