Monday, March 19, 2012

Microsoft Access Query converted to SQL

Here a query Microsoft Access Query That I would like to convert to SQL. What replace the Word "Last" in SQL

SELECT Contacts.FirstName,Last(Contacts.LastName) AS LastofLastName
FROM Contacts
GROUP BY Contacts.FirstName;

You can try a ORDER BY on lastname column with TOP 1 or Max(LastName).

SELECT Contacts.FirstName,Max(Contacts.LastName) AS LastofLastName
FROM Contacts
GROUP BY Contacts.FirstName

Or

SELECT TOP (1) Contacts.FirstName, Contacts.LastName AS LastofLastName
FROM Contacts
ORDER BY Contacts.LastName DESC

|||Thanks. It works fine on both.

No comments:

Post a Comment