Hello,
I have the following table.
Column1 Column2 date
110913 8048 9/15/2015
110913 8036 9/30/2015
110652 1011 10/19/2015
110652 1011 10/10/2015
110009 1016 7/1/2015
110009 1087 6/20/2015
110888 7171 4/1/2015
I needed it to get the earliest date from the above table based on column 'Column1'. With help from somebody, came up with the following query and works perfectly
with Min_Record as
(
select Table1.Column1, Table2.Column2, Table2.date, row_number() over(partition by t.Table1.Column1 order by Table2.date asc) as rn
from Table2 INNER JOIN Table1 ON Table1.Entry = Rable2.Entry
)
select m.Column1, m.Column2, Table2.Date
from Min_Record m
where m.rn = 1;
It generates this output:
Column1 Column2 date
110913 8048 9/15/2015
110652 1011 10/10/2015
110009 1087 6/20/2015
110888 7171 4/1/2015
Now what happens when there are no information exist in Table2 when Column1 = 110888. How to add a code to above query that produces the following output (adding line '----').
Column1 Column2 date
110913 8048 9/15/2015
110652 1011 10/10/2015
110009 1087 6/20/2015
110888 ---- ----
Any help would be greatly appreciated.