SQL select earliest rows where column is Null

Hi, I have an SQL pricing table where one of the columns is date, another is the price information.

How do I select the row with earliest date where the price is null?

Additional requirement:

There are multiple funds in the table, each fund can have different date which the earliest date is null. How do I display all these rows with the earliest date?

E.g. Fund 1, 23 January
Fund 2, 10 March
Fund 3, 9 April

These dates are the earliest dates for each fund that price is null.

I am currently using this code

select dbo.Benchmark_Details.BenchmarkID, Date from dbo.Benchmark_Details where date in
(select top 1 date from dbo.Benchmark_Details where Benchmark_Price is null order by date)

but this takes the earliest of all the dates and applies it to all the funds instead of each fund having its earliest date individually

Any help?

Hi @DEATHFISH - In SQL the inner query will execute first (select top 1 date from dbo.Benchmark_Details where Benchmark_Price is null order by date)
then it result will pass to the the outer query to execute.

You need to do something like groupby or Having statement.

Hope it will help you.

Best!!
Anmol

Hi @anmolk171 do you have a sample query? Thanks

Hi @DEATHFISH -
For group by refer this link.
https://www.w3schools.com/sql/sql_groupby.asp

For Having refer this link.
http://www.sqlservertutorial.net/sql-server-basics/sql-server-having/

Hope it will help you and other way around is providing me thedata.

Best!!
Anmol