Questions tagged [mysql-error-1241]

MySQL error 1241: Operand should contain n column(s)

You can get MySQL error 1241 when your operand contains the wrong number of expected columns.

A subselect returns 3 columns, but only two are expected:

SELECT * FROM yourtable
WHERE (id, type) IN (SELECT id, type, name FROM table2)
       ^^  ^^^^             ^^  ^^^^  ^^^^
       2 columns              3 columns

or if you are using the wrong syntax:

INSERT INTO table2 (Name, Address)
SELECT (Name, Address)
FROM table1;

(it should be just SELECT Name, Address FROM ...)

or also this one:

SELECT id, (SELECT name, address FROM table2
            WHERE table2.id=table1.id ORDER BY id LIMIT 1)
FROM table1

should be written as:

SELECT
  id,
  (SELECT name FROM table2 WHERE table2.id=table1.id ORDER BY id LIMIT 1),
  (SELECT address FROM table2 WHERE table2.id=table1.id ORDER BY id LIMIT 1)
FROM table1
77 questions
127
votes
11 answers

MySQL - Operand should contain 1 column(s)

While working on a system I'm creating, I attempted to use the following query in my project: SELECT topics.id, topics.name, topics.post_count, topics.view_count, COUNT( posts.solved_post ) AS solved_post, (SELECT users.username AS posted_by, …
user1543386
75
votes
3 answers

MySQL error 1241: Operand should contain 1 column(s)

I am trying to Insert data from a table1 into table2 insert into table2(Name,Subject,student_id,result) select (Name,Subject,student_id,result) from table1; Key for table2 is student_id. Assume that there are not any duplicates. I get the error:…
Kumaran Senapathy
  • 1,233
  • 4
  • 18
  • 30
24
votes
5 answers

MySQL Syntax error message "Operand should contain 1 column(s)"

I tried running the following statement: INSERT INTO VOUCHER (VOUCHER_NUMBER, BOOK_ID, DENOMINATION) SELECT (a.number, b.ID, b.DENOMINATION) FROM temp_cheques a, BOOK b WHERE a.number BETWEEN b.START_NUMBER AND b.START_NUMBER+b.UNITS-1; which, as…
Elie
  • 13,693
  • 23
  • 74
  • 128
11
votes
5 answers

MySQL Error "Operand should contain 1 column"

I could find a lot of similar questions but no real solution for my problem. My SQL query: UPDATE ADRESSEN SET EMAIL = 0 WHERE ID = (SELECT ID, COUNT(ID) AS COUNTER FROM EIGENSCHAFTEN WHERE Kategorie = "BOUNCE" GROUP BY ID HAVING COUNTER = 1) The…
jacob
  • 127
  • 1
  • 1
  • 5
10
votes
1 answer

Mysql ERROR 1241 (21000): Operand should contain 1 column(s)

I have Customer Groups with Number-Ranges (from Customernumber, to Customernumber). select g.id, (select count(*), sum(sales) FROM transactions t1 where t1.customernumber between g.from_customernumber and g.to_customernumber) from customer_groups…
Marco
  • 3,470
  • 4
  • 23
  • 35
7
votes
4 answers

Is it possible for a subquery to return two values?

Is it possible for a subquery to return two values onto the outer query? Such as: SELECT 1, (SELECT COUNT(*), MAX(*) FROM test_table WHERE test=123) FROM another_table Or is there a better way to do this?
user499054
7
votes
2 answers

Error #1241 - Operand should contain 1 column(s) in Mysql

I just try following query: SELECT *, ( SELECT count(*) FROM users where users.email=calls.email ) as ureg, ( SELECT sum(qty) FROM product where product.owner in (SELECT *…
dpfarhad
  • 75
  • 1
  • 1
  • 6
4
votes
3 answers

Operand Should Contain 1 Column - MySQL NOT IN

SELECT * from campaigns WHERE id not in (SELECT e.id_campaign, d.name, d.frequency, d.country, d.referral, d.bid, d.status, COUNT(e.id) AS countcap FROM campaigns d LEFT JOIN served e ON d.id = e.id_campaign WHERE …
reefine
  • 873
  • 2
  • 13
  • 25
4
votes
3 answers

Operand should contain 1 column(s) in java

String sql = "SELECT (Employee_name, Password) FROM employee WHERE (Employee_name = '"+name+"' AND Password = '"+password+"')"; and getting the following exception in JSP java.sql.sqlexception insert operand should contain 1 column(s) Please…
user3507176
  • 41
  • 1
  • 1
  • 3
4
votes
2 answers

Error #1241 - Operand should contain 1 column(s)

I am trying this QUERY, and return this weird error. What does it mean? Here is my query: SELECT * FROM newRowP a WHERE a.rowId IN (SELECT * FROM newCellP b WHERE b.cellId IN (SELECT * FROM newproviderP c WHERE c.pId IN ('3000344','245')))
superTramp
  • 165
  • 2
  • 3
  • 11
3
votes
1 answer

MySQL INSERT Error Operand should contain 1 column

I have this MySQL insert query that is giving me a Error Code: 1241. Operand should contain 1 column(s). INSERT INTO esjp_content ( esjp_content.primary_key, esjp_content.template_id, esjp_content.section_ref, esjp_content.position,…
Jim Fell
  • 13,750
  • 36
  • 127
  • 202
3
votes
1 answer

ERROR 1241 (21000): Operand should contain 1 column(s) when executing query

INSERT INTO People(Track_id_Reference) SELECT track_id FROM Tracks WHERE track_title IN (SELECT tracktitle FROM top100 WHERE artist IN (SELECT p.People_name, t.artist …
Anvesh Raavi
  • 303
  • 1
  • 3
  • 14
3
votes
1 answer

MYSQL trigger to select from and update the same table gives error #1241 - Operand should contain 1 column(s)

when i try to select and update the same table mysql gives error error #1241 - Operand should contain 1 column(s) The trigger is DELIMITER $$ CREATE TRIGGER visitor_validation BEFORE INSERT ON ratingsvisitors FOR EACH ROW BEGIN SET @ifexists =…
Bipin Chandra Tripathi
  • 2,550
  • 4
  • 28
  • 45
2
votes
1 answer

If else in stored procedure in mysql

Hello guys I'm little bit confuse. I just want to ask if this is the right syntax. I try the if else stored proc queries in other posts but its not working. CREATE PROCEDURE `addBarberCommission`(IN `empID` INT, IN `ioIN` VARCHAR(11)) BEGIN INSERT…
boldsinas101
  • 300
  • 2
  • 5
  • 22
2
votes
2 answers

How to select and update a record at the same time in mySQL?

Is there any way to select a record and update it in a single query? I tried this: UPDATE arrc_Voucher SET ActivatedDT = now() WHERE (SELECT VoucherNbr, VoucherID FROM arrc_Voucher WHERE ActivatedDT IS NULL AND…
EmmyS
  • 11,892
  • 48
  • 101
  • 156
1
2 3 4 5 6