I’m new to sql, and came across a little problem.
I have a query that goes like this:
select cust_id, count(1) from all_customers
group by cust_id
having count(1)>4;
that query gives me the result i want.
I need to make a new query of all the customers in all_customers table, and exclude the result I just got from the query above.
I tried doing something like this:
select * from all_customers
where cust_id NOT IN
(
select cust_id, count(1) from all_customers
group by cust_id
having count(1)>4
)
But I get the error message too many values.
What am I doing wrong?
You should get rid of the aggregated column in your
NOT INclause. The reason is you are only comparingcust_idcolumn. Also note that when usingNOT IN, a subquery should always return single column.