# Database Discussions > MySQL >  Need help with a query

## shameerpv

I have 2 table
first table.  employee( empid- primary key ,empname)
eg: employee table
1 john
2 martyn
3 davis

second table documents(empid,documentname)
eg : 
1 address.doc
1 worksheet.doc
1 salaryslip.doc
3 address.doc


each employee have only one entry in employee table
but in document table , zero or more entries are inserted for each employee.

i want to write a query that gives an output shown in below

empid  empname   documentflag
1         john          true
2         martyn       null
3         davis        true

that is, if documents table have at least one entry for an employee ,then set corresponding document flag is true. otherwise set document value as null

----------


## Civic1986

select a.empid,a.empname,count(b.empid) from employee a,documents b 
where a.empid=b.empid group by a.empid,a.empname,b.empid

----------


## b_pereira

Try this: 
 select e.name, if(count(d.document_name)>0,'True','False') as flag from employee e left join document d on e.name = d.employee group by e.name;

Bert

----------

