Inserting with WHERE and AND, Error Code: 1241. Operand should contain 1 column(s)

159 views Asked by At

Getting an error saying: Error Code: 1241. Operand should contain 1 column(s)

INSERT INTO TBL_TESTER_INFO2 (
    board_id,
    tester_name,
    board_name, 
    config,
    operating_system,
    log_created
) VALUES (
    (SELECT
        bl.id as 'board_id',
        bl.tester_type,
        bl.board_name
    FROM TesterDeviceMatrix.TBL_BOARD_LIST bl
    WHERE bl.tester_type = 'UFLEX'
    AND bl.board_name = 'HSD-U'
    ), 
    'tester',
    'board',
    'slot',
    'windows',
    '2015-06-10 16:08:42'
);

Any help on this? There seems to be no syntax error.

2

There are 2 answers

1
Phil On BEST ANSWER

Pretty sure you can't mix a SELECT statement with other values as part of an INSERT statement's VALUE set.

I'd just put the static values into the SELECT, eg

INSERT INTO TBL_TESTER_INFO2 (...)
SELECT
    bl.id,
    bl.tester_type,
    bl.board_name,
    'slot',
    'windows',
    '2015-06-10 16:08:42'
FROM TesterDeviceMatrix.TBL_BOARD_LIST bl
WHERE bl.tester_type = 'UFLEX'
AND bl.board_name = 'HSD-U';
0
Venkatesh Panabaka On

Here is the syntax of insert select SQL.

INSERT INTO table_name1(id, name,address,contact_number) 
SELECT id, name, address, contact_number FROM table_name2;  

In your SQL insert statement columns are not matching in select SQL.

I modified your SQL. I think it will execute

INSERT INTO TBL_TESTER_INFO2 (board_id,tester_name,board_name, config,operating_system,log_created) 
    SELECT bl.id AS 'board_id',bl.tester_type,bl.board_name,'slot','windows','2015-06-10 16:08:42'
    FROM TesterDeviceMatrix.TBL_BOARD_LIST bl
    WHERE bl.tester_type = 'UFLEX'
    AND bl.board_name = 'HSD-U'

Thank you.