Error 1241 operand should contain 1 column s что означает
How to fix MySQL operand should contain 1 column(s) error
Learn how to fix MySQL error operand should contain 1 column(s)
Posted on October 06, 2021
The error Operand should contain 1 column(s) is most likely caused by a subquery that’s returning more than one column.
Here’s a typical SELECT query that causes this error:
Most often, you only need to check your subquery and make sure that it returns only one column.
If you need more guidance on how to fix this MySQL error, then you may read the next section.
How to fix Operand should contain 1 column(s) error
The members table contain the first_name of people who have pets as shown below:
While the pets table contain the owner and the species column as follows:
The first_name and the owner columns are related, so you may use a subquery to display data from both tables like this:
However, the above SQL query is wrong, and it will throw an error like this:
This is because MySQL expects the subquery to return only one column, but the above subquery returns two.
To fix the error, you may create two subqueries with each subquery returning only one column as in the following SELECT statement:
While the above query works, it will throw another error once the subquery returns more than one row.
Let’s add another pet that’s owned by “Jessie” to the pets table as shown below:
Now the subqueries will return two species and age rows for “Jessie”, causing another related error:
To properly fix the error, you need to replace the subquery with a JOIN clause:
Subqueries can be used to replace JOIN clauses only when you need to SELECT data from one table, but you need to filter the result by another table column.
For example, maybe you have some owner names in the pets table that aren’t recorded in the members table. You can use a subquery in the WHERE clause to display rows in the pets table that are also recorded in the members table.
Here’s an example of using a subquery in the WHERE clause:
Without using a subquery, you need to JOIN the table as shown below:
The two queries above will produce the same result set.
And that’s how you can fix the Operand should contain 1 column(s) error in MySQL.
You need to check your subquery before anything else when you encounter this error.
Level up your programming skills
I’m sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I’ll send new stuff straight into your inbox!
About
Nathan Sebhastian is a software engineer with a passion for writing tech tutorials. Learn JavaScript and other web development technology concepts through easy-to-understand explanations written in plain English.
Получение ошибки «Operand should contain 1 column(s)» по этому запросу
Итак, у меня есть код ниже:
2 ответа
Это, вероятно, дубликат другого вопроса, но я не могу понять, как исправить эту ошибку, даже следуя указаниям ответов. У меня есть две таблицы, и вторая должна содержать часть столбцов первой. Вот их схемы (учтите, что я пропустил некоторые столбцы, которые мне не нужны) : Первый Стол ID | num |.
Ошибка совершенно очевидна : в вашем подзапросе не может быть более одного поля, очевидно, что вы сопоставляете поле с одним столбцом. Поэтому просто переместите SUM в предложение HAVING :
Похожие вопросы:
Получаю сообщение об ошибке: 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 (.
создайте функцию в mysql, когда функция вызывается, я получил Error Code: 1241 Operand should contain 1 column(s), как решить ошибку drop function if exists age; DELIMITER // CREATE FUNCTION age.
Это, вероятно, дубликат другого вопроса, но я не могу понять, как исправить эту ошибку, даже следуя указаниям ответов. У меня есть две таблицы, и вторая должна содержать часть столбцов первой. Вот.
Это мой запрос mysql. Кто-нибудь знает, что это за ошибка и как ее исправить? Спасибо. SQL query: Documentation INSERT IGNORE INTO thread_user (thread_id,user_id,last_read_date) SELECT 24,1,NOW().
Я написал длинную хранимую процедуру, когда я ее вызываю, я получаю следующую ошибку: ERROR 1241 (21000): Operand should contain 1 column(s) есть ли способ определить, какая команда в этой хранимой.
прошло уже много времени с тех пор, как я использовал sql, нужно немного подтолкнуть. получил 2 таблицы, пользователей и голосов users
Я пытаюсь визуализировать данные на сплайновой диаграмме, собирая массив идентификаторов: Контроллер def student_feedback difficulty_ids =.
Я пытаюсь визуализировать данные на сплайновой диаграмме, собирая массив идентификаторов: Контроллер def student_feedback difficulty_ids =.