#1241 – Operand should contain 1 column(s)
SELECT name
FROM tabel
WHERE n1 IN (
SELECT key1,key2,key3
FROM tabel2
)
but if try :
SELECT name
FROM tabel
WHERE n1 IN ('1','2','5')
its work
thanks
#1241 – Operand should contain 1 column(s)
SELECT name
FROM tabel
WHERE n1 IN (
SELECT key1,key2,key3
FROM tabel2
)
but if try :
SELECT name
FROM tabel
WHERE n1 IN ('1','2','5')
its work
thanks
2
Answers
You can not use queries which return more than 1 column if you want to use the result in an IN clause
Try something like this if you want to match against all 3 Keys:
Explanation:
This works because its a list of values:
This does not work:
The query returns a list of results instead of single values:
The reason is, in your second working query, the
IN ('1','2','5')
returns a set of 3 values to test the predicate against.Your first query does not work because it’s invalid for use by the
IN
operator, which requires a set of values.If you think about it, the first query cannot possibly work because
key1,key2,key3
are 3 different columns and each could be a different data type, sokey1
could be an integer andkey2
could be a date andkey3
could be boolean….This query could return 1000 rows of 3 columns so 3000 potentially conflicting types of data, how would
IN
know what to do with that!