tags:

views:

32

answers:

2

I am writing an query in sql and getting an error:

Invalid use of group function

What does it mean? In my query, where clause is given below:

select c.name,s.contact,s.number
from list c , senior s
where c.id = s.id AND c.name = 'Abg' AND c.state ='qw' AND MIN(c.dob);

Basically, I have 2 files and I need to find the younger customer from 2nd file and then have to retrieve its data from first file. I have the ID number of customers in 2nd file. I first check the ids with the id of first file. And check its state and name. And then I need to find younger among those customers.Thats Why i need MIn function.

A: 

AND MIN(c.dob); is causing the error.

I think you should use something like:

c.dob = (select MIN(dob) from c);
codaddict
"And then I need to find younger among those customers." implies the where constrains should be used when finding the min value of dob.
Goran
A: 

You need to use a subquery:

 select c.name,s.contact,s.number
 from  from list c, senior s
 inner join
 (
    select MIN(c.dob) minDob
           ,c.id
    from list c
    where c.id = s.id AND c.name = 'Abg' AND c.state ='qw'
    group by c.id 
 ) sq
 on c.dob = sq.minDob
    and c.id = sq.id
Goran