I am trying to execute an SQL statement that I am planning on using with a PL/SQL cursor down the road. It will fetch an employees name and the projects they are working on if they are working on more than 1 project. For some reason, the "having count(pno)>1" stipulation will not work here. It just says "no data found"
Is there anything I'm doing wrong? I included my DB code below the query.
Query:
select pname, fname
from project, works_on, employee
where pno=pnumber and essn=ssn
group by pname, fname
having count(pno)>1;
Works_on table:
create table works_on (
Essn char(9) not null,
Pno int not null,
hours decimal(3,1),
primary key(essn, pno),
foreign key(Essn) references employee,
foreign key(pno) references project);
Project table:
create table project (
Pname varchar2(15) not null,
Pnumber int not null,
Plocation varchar2(15),
Dnum int not null,
primary key (Pnumber),
unique (Pname),
foreign key(Dnum) references department(Dnumber));
Employee table:
create table employee (
Fname varchar2(15) not null,
Minit char(1),
Lname varchar2(15) not null,
Ssn char(9),
Bdate date,
Address varchar2(30),
Sex char(1),
Salary decimal(10,2),
super_ssn char(9),
dno int,
primary key (Ssn),
foreign key (dno) references department(Dnumber));
EDIT
I managed to make this work instead:
select fname, pname
from employee, works_on, project
where essn=ssn and pno=pnumber
group by fname, pname
having count(pnumber) > 1
What made pnumber work in place of pno?
pnocolumn - in which case returning zero rows would be correct for theHAVING COUNT(pno) > 1filter.