Search code examples
mysqlsqlinsertinsert-select

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


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.


Solution

  • 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';