Subject | Re: [firebird-support] Calling a SP without modify the 'from ***' statement |
---|---|
Author | Helen Borrie |
Post date | 2010-01-27T10:16:39Z |
At 08:26 PM 27/01/2010, you wrote:
First, make a DESCENDING index on documents.creation_time and commit work.
Then:
select u.ID,
(select FIRST d.ID from documents d
where d.ID = u.ID
ORDER BY d.creation_time DESC) as LAST_DOC_ID
from users u
where u.ID = ?
If you are using Firebird 2 or higher, and you need more than one field from that document record, read up on Derived Tables in the release notes or the Language Update Reference.
./heLen
>hi all, i have this 2 table (there i simplify them)You don't need a procedure - you can get this set directly in DSQL:
>
>Users
>{
> integer ID
>}
>
>Documents
>{
> integer ID,
> integer USER_ID //it's a FK
> timestamp CREATION_TIME
>}
>
>now i have this query
>
>select u.ID from Users u
>
>i need to modify that to have also the last document but i can change only the select statement, not the from ***,
>so i think to write a procedure (it's pseudo-code)
>
>integer GET_ID_OF_LAST_DOCUMENT_FOR_THIS_USER(integer userID)
>
>and use a select as
>
>select u.ID, GET_***_USER(u.ID) from User u
>
>but i try a bit but it seems impossible, i'm right or exists same way to call a procedure in the 'SELECT ***' statement without change the 'FROM ***' ?
First, make a DESCENDING index on documents.creation_time and commit work.
Then:
select u.ID,
(select FIRST d.ID from documents d
where d.ID = u.ID
ORDER BY d.creation_time DESC) as LAST_DOC_ID
from users u
where u.ID = ?
If you are using Firebird 2 or higher, and you need more than one field from that document record, read up on Derived Tables in the release notes or the Language Update Reference.
./heLen