Subject Re: [firebird-support] Way to avoid many subselects
Author Arno Brinkman
Hi,

> Very tricky :-) I would never imagine this. Thank you!
>
> Just for curiosity, do you figure out some way to do the same thing if i
> can't use the ID?
> for instance, if i want to order by invoice date desc and the table can have
> duplicate dates for the same customer?

SELECT
r.RDB$RELATION_NAME,
rf.RDB$FIELD_NAME
FROM
RDB$RELATIONS r
LEFT JOIN RDB$RELATION_FIELDS rf ON (rf.RDB$RELATION_NAME = r.RDB$RELATION_NAME and
rf.RDB$FIELD_NAME =
(SELECT FIRST 1 srf.RDB$FIELD_NAME
FROM RDB$RELATION_FIELDS srf
WHERE srf.RDB$RELATION_NAME = r.RDB$RELATION_NAME
ORDER BY srf.RDB$FIELD_ID ASC))

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
General database development support:
http://www.databasedevelopmentforum.com

Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Firebird and Interbase users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info