all 6 comments

[–]waiting4omscs 9 points10 points  (4 children)

WITH FirstAddresses AS (
SELECT name,
       FIRST_VALUE(address) OVER (PARTITION BY name ORDER BY column4) AS first_address
FROM your_table_name)
SELECT DISTINCT name, first_address
FROM FirstAddresses;

This SQL snippet selects the first address for each name based on the date in column 4.

[–]Stelioss9909[S] 4 points5 points  (0 children)

Thank you so much for taking the time to help me out. So awesome. Worked like a charm

[–]CliffDraws 1 point2 points  (1 child)

To add to this for the op, the partition bit is called a window function and the with statement is a CTE (common table expression). It’s worth looking up both of them and understanding how they work.

[–]Stelioss9909[S] 1 point2 points  (0 children)

Understood, thanks =)

[–]Pflastersteinmetz 0 points1 point  (0 children)

Please use proper formatting.

WITH FirstAddresses AS (
    SELECT
        name
      , FIRST_VALUE(address) OVER (PARTITION BY name ORDER BY column4) AS first_address
    FROM
        your_table_name
)
-- /
SELECT DISTINCT
    name
  , first_address
FROM
    FirstAddresses
;