Reputation: 81
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
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
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
Reputation: 7673
You have use WHEN
instead of WHERE
SELECT * FROM `Table` WHERE `ID` IN (SELECT `Units` FROM `Table2`)
Upvotes: 4