Subject Re: [firebird-support] last of the SQL
Author Ismael L. Donis García
If, I believe that this is the best-suited form to do the trick.

Thank you very much.

=========
¦¦ ISMAEL ¦¦
=========

----- Mensaje original -----
De: Svein Erling Tysvær
Para: firebird-support@yahoogroups.com
Enviado: miércoles, 30 de septiembre de 2009 01:56
Asunto: RE: [firebird-support] last of the SQL


Firebird works on data sets and in a set there is no default understanding of FIRST or LAST. So there are several possible answers to your question:

This gets the last address alphabetically sorted according to the current collation:

select staff.name, max(staff.address) as address from staff
group by staff.name order by staff.name

This gets the last address depending on MoveDate, or the highest primary key if a person moved twice on the same date (OK, that's unlikely, but in different situations it may be good to know how to randomly pick one in case of equality):

select s1.name, s1.address from staff s1
where not exists(select * from staff s2
where s2.name = s1.name
and (s2.MoveDate > s1.MoveDate
or (s2.MoveDate = s1.MoveDate
and s2.PrimaryKeyField > s1.PrimaryKeyField)))

HTH,
Set

-----Original Message-----
From: firebird-support@yahoogroups.com [mailto:firebird-support@yahoogroups.com] On Behalf Of Ismael L. Donis Garc?a
Sent: 24. september 2009 09:51
To: firebird-support@yahoogroups.com
Subject: [firebird-support] last of the SQL

What show substitutes the show last of the SQL?

Example: select staff.name, last(staff.address) as address from staff group
by staff.name order by staff.name

Regards
=========
¦¦ ISMAEL ¦¦
=========




[Non-text portions of this message have been removed]