SQL query, requires a series of rows

Hi guys, I have the following table structured as follows:

row structure

So basically, as you can see, the department goes through name changes every couple of years. Look, for example, at number 16. I want to select a query that will only receive a name when the date is the largest. How to do it?

+5
source share
4 answers
select ID, Name from departments o 
where o.thedate=
  (select max(i.thedate) from departments i where o.id=i.id)
+5
source
SELECT ID, 
First(Name) AS FirstOfName, First(DateChange) AS FirstOfDateChange
FROM departments
GROUP BY ID
ORDER BY First(DateChange) DESC;
+1
source

? .

SELECT
    id,
    name,
    date
FROM table
WHERE name = (SELECT TOP 1 name
              FROM table AS subtable
              WHERE subtable.name = table.name
              ORDER BY date DESC)
0

SELECT d. * INNER JOIN (SELECT pk                      GROUP BY ID            aDate = MAX (theDate)) m ON m.pk = d.pk WHERE [Name] = "Department"

0

All Articles