user1966593
user1966593

Reputation: 81

SQL IN Operator with Select

I want to use the IN Operator in SQL with a select statement but I get the following error "Cannot perform an aggregate function on an expression containing an aggregate or a subquery."

The code that I am using looks as follows:

select * from Table where ID in (select Units from Table2)

Upvotes: 1

Views: 278

Answers (3)

Marko
Marko

Reputation: 1

You should try to select specific ID columns in your second query, something like this:

Select*from Table where ID IN (Select ID from Table2)

Upvotes: 0

Jainendra
Jainendra

Reputation: 25153

You should use where in place of when in your query. The correct query will be:

select * from Table where ID in (select Units from Table2)

Upvotes: 1

xylar
xylar

Reputation: 7673

You have use WHEN instead of WHERE

SELECT * FROM `Table` WHERE `ID` IN (SELECT `Units` FROM `Table2`)

Upvotes: 4

Related Questions