2

I am trying to use the "IN" SQL operator but instead of a set number of defined variables, I'm trying to use a table column instead. So I've written the following, but I cannot get it work.

SELECT * FROM searchWithinTable
WHERE searchBy IN (Test2C.col1)

Any help is appreciated, Thanks! (I'm using SQL Server)

Anuj Tripathi
  • 2,251
  • 14
  • 18

2 Answers2

5

You can't pass "column" as a list for in condition, but you can pass subselect from that table/column.

Just use something like this:

SELECT * FROM searchWithinTable
WHERE searchBy IN (select col1 from Test2C)
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
0

use sub query instead of static value

example:=

SELECT EMPID, ENAME
FROM EMPLOYEES 
WHERE EMPID IN (SELECT EMPID FROM EMPLOYEES WHERE EMPID >200)