omega
omega

Reputation: 43843

Operand should contain 1 column error in mysql

This is my mysql query. Does anyone know what the error is and how to fix it?

Thanks.

SQL query: Documentation

INSERT IGNORE
INTO thread_user (thread_id,user_id,last_read_date)
SELECT 24,1,NOW()
UNION
SELECT 24, b.a, NOW()
FROM (SELECT (2,3,4) AS a) b

MySQL said: Documentation
#1241 - Operand should contain 1 column(s) 

Upvotes: 1

Views: 766

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269753

I am guessing that you want three rows in the second subquery. The expression (2, 3, 4) is causing the error.

INSERT IGNORE INTO thread_user(thread_id,user_id,last_read_date)
    SELECT 24, 1, NOW()
    UNION ALL
    SELECT 24, b.a, NOW()
    FROM (SELECT 2 as a UNION ALL
          SELECT 3 UNION ALL
          SELECT 4 
         ) b;

This is just a guess on your intentions. Note that the outer UNION can be UNION ALL -- you should always use the latter unless you want to incur the overhead of removing duplicates.

Upvotes: 2

Related Questions