0

I have a SQL table with the following columns:

|    Date    |    Pass/Fail    |
--------------------------------
| yyyy-mm-dd |      PASS       |   

| yyyy-mm-dd |      FAIL       |

How do I obtain the value in the "Date" column of the row with the first occurrence (ordered by date) of "PASS" in the "Pass/Fail" column?

2 Answers2

1

You can use order by with limit 1

select * from tablename
where PassFailCol='Pass'
order by date
limit 1
Fahmi
  • 37,315
  • 5
  • 22
  • 31
0

If you wanted to also capture more than one passing record should two or more records be tied as being first, then we can try using a subquery:

SELECT Date, PassFail
FROM yourTable
WHERE
    PassFail = 'Pass' AND
    Date = (SELECT MIN(Date) FROM yourTable WHERE PassFail = 'Pass');
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360