Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL SELECT when child table contains zero rows

Let's say I have two tables:

Table A
employeeID (int)
employeeName (varchar)
employeeDOB (varchar)

Table B
employeeID (int)
holidaysUsed (int)

Table B is relational to Table A via employeeID. Table B can have zero or more rows linked to a single employeeID. I'd like to perform a SELECT on Table A but only retrieve rows in Table A when there are no corresponding records in table B.

I have a few ideas on this but I'd like to ensure I'm using the optimum query. Any help would be much appreciated.

Additional Information

Database platform: SQL Server 2008 R2

Typical returned dataset size 1000 records avg.

like image 266
QFDev Avatar asked Sep 27 '26 15:09

QFDev


1 Answers

SELECT * FROM A WHERE employeeID NOT IN (SELECT employeeID FROM B);

like image 159
bardo Avatar answered Sep 30 '26 05:09

bardo