0

Hi i have this query but its giving me an error of Operand should contain 1 column(s) not sure why?

Select *, 
(Select *
FROM InstrumentModel
WHERE InstrumentModel.InstrumentModelID=Instrument.InstrumentModelID)
FROM Instrument
2
  • Can you paste exact error message you are getting? Commented Mar 2, 2014 at 18:15
  • Error Code: 1241. Operand should contain 1 column(s) Commented Mar 2, 2014 at 18:16

3 Answers 3

1

according to your query you wanted to get data from instrument and instrumentModel table and in your case its expecting "from table name " after your select * .when the subselect query runs to get its result its not finding table instrument.InstrumentModelId inorder to fetch result from both the table by matching you can use join .or you can also select perticuler fields by tableName.fieldName and in where condition use your condition.

like :

 select Instrument.x,InstrumentModel.y
 from instrument,instrumentModel
 where instrument.x=instrumentModel.y 
Sign up to request clarification or add additional context in comments.

1 Comment

Please don't use the outdated implicit joins in the where clause. Use the modern explicit JOIN syntax
0

You can use a join to select from 2 connected tables

select *
from Instrument i
join InstrumentModel m on m.InstrumentModelID = i.InstrumentModelID

Comments

0

When you use subqueries in the column list, they need to return exactly one value. You can read more in the documentation

as a user commented in the documentation, using subqueries like this can ruin your performance:

when the same subquery is used several times, mysql does not use this fact to optimize the query, so be careful not to run into performance problems.

example:

SELECT col0, (SELECT col1 FROM table1 WHERE table1.id = table0.id), (SELECT col2 FROM table1 WHERE table1.id = table0.id) FROM table0 WHERE ...

the join of table0 with table1 is executed once for EACH subquery, leading to very bad performance for this kind of query.

Therefore you should rather join the tables, as described by the other answer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.