Toad World® Forums

SQL UNION Help - Only see records when both side of Union has records

PLTC.Classification,

PLTC.Task,

PLTC.Employee,

PLTC.[Date Logged],

PLTC.[Hours Logged],

PLTC.[Billing Rate]

INNER JOIN

Dovico.dbo.Employee Employee

WHERE ((PLTC.[Week Ending] = calendar__gregorian__last_7_days__)

UNION

PLTC.Classification,

PLTC.Task,

PLTC.Employee,

PLTC.[Date Logged],

PLTC.[Hours Logged],

PLTC.[Billing Rate]

INNER JOIN

Dovico.dbo.Employee Employee

WHERE ((PLTC.[Week Ending] = calendar__gregorian__last_7_days__)

AND (PLTC.Task = ‘Lieu Time (zero charge)’))

ORDER BY PLTC.Employee

Hello,

How can I adapt the following SQL script (see below), so only those employee records are retuned if both side of the Union have rows returned.

The first select statement brings back last weeks overtime, while the second select statement brings back any lieu time taken last week.

What I’m looking for are only those employees how have worked overtime and had a lieu time off during last week.

Any help and advise welcome.

Thank you in advance.

Regards

David

SELECT PLTC.[Week Ending],FROM Dovico.dbo.PLTC PLTCON (PLTC.Employee = Employee.EMPLOYEE)AND (PLTC.[Billing Rate] != ‘Standard Rate’))

SELECT PLTC.[Week Ending],FROM Dovico.dbo.PLTC PLTCON (PLTC.Employee = Employee.EMPLOYEE)AND (PLTC.Classification = ‘Absence’)