Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: query issue

Re: query issue

From: Ed Prochak <ed.prochak_at_magicinterface.com>
Date: Thu, 29 Jan 2004 18:37:46 -0500
Message-ID: <4rgSb.51$rK6.0@fe02.usenetserver.com>


Billy Verreynne wrote:

> 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.
>
>
> --
> Billy

Actually, given his sample data, I believe he would get 1231456 61
1231456 62
1231456 63
since each ROW is distinct.
-- 
Ed Prochak
running    http://www.faqs.org/faqs/running-faq/
netiquette http://www.psg.com/emily.html
--
"Two roads diverged in a wood and I
I took the one less travelled by
and that has made all the difference."
robert frost
Received on Thu Jan 29 2004 - 17:37:46 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US