Hi guys, I have the following table structured as follows:
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?
select ID, Name from departments o where o.thedate= (select max(i.thedate) from departments i where o.id=i.id)
SELECT ID, First(Name) AS FirstOfName, First(DateChange) AS FirstOfDateChange FROM departments GROUP BY ID ORDER BY First(DateChange) DESC;
? .
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)
SELECT d. * INNER JOIN (SELECT pk GROUP BY ID aDate = MAX (theDate)) m ON m.pk = d.pk WHERE [Name] = "Department"