I have one table in my Database that has column names: buildNumber, result, versionStatus. Now in my SQL statement I want to display the ‘buildNumber’ where the ‘versionStatus’ is old and the ‘result’ is pass and where the versionStatus is new and the result is ‘fail‘. So I want to display anything that has a result of fail today but had a result of pass last time. So if I have these records in the DB (column separated by –):
build2--pass--old
build2--fail--new
The SQL statement should only display “build2” because it passed with “old” but now ‘failed’ with new version.
I have tried:
select *
from CSAResults.dbo.Details
where result = 'pass'
and versionStatus = 'Old'
and versionStatus IN (select CSAResults.dbo.Details.versionStatus
from CSAResults.dbo.Details
where versionStatus = 'New'
and result = 'fail')
but nothing is returned.
Thanks
This query does a self-joins of Details table to get the result you want.
I added the distinct in the select clause so you wouldn’t get duplicate results if there were multiple old versions of the build that had passed