Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: query issue
josephcurwen_at_despammed.com (curwen) wrote:
> I'm in deep struggle with query from a huge table:
Huge is relative. :-)
> what I've got is a lot of records like:
>
> _______________
> numb fk1
> _______________
> 1231456 61
> 1231456 62
> 1231456 63
> 1231456 61
>
> from my view I should only get the last record:
> __________
> 123456 61
Use a GROUP BY the foriegn key and select MAX (the last) number. E.g.
SELECT
MAX(numb) "NUMB",
fk1
FROM relatively_huge_table
GROUP BY fk1
> last has to be intended as inserting order, there's not sorting defined on data
> the table has also a progressive id generated by a sequence..
To add to what Daniel said.. in a blunt way using nice friendly letters... empty your cup of preconceptions of what you think a RDBMS is and then fill it with some RTFM'ing.
> I've tried the the following , but doesn't work:
>
> select distinct numb,fk1
> from <table>
It does work - just not the way you think. :-)
You are aksing for distinct/unique values - for *both* number and
foreign key. Thus you will get:
123456 61
123457 61
Both these are unique.
-- BillyReceived on Wed Jan 28 2004 - 23:34:43 CST
![]() |
![]() |