Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2008
    Posts
    9

    Unanswered: Comparing two records!!

    Hi,

    I have a scenario as below:


    utcode utytype data
    1 A klkk
    1 B lkk
    1 C ijij
    2 B njknk
    2 C vvv
    3 C fcf

    My output needs to be

    1 A klkk
    2 B njknk
    3 C fcf

    Could you please provide me the sql for achieving this?

    If utctype equals to utctype of next record then the first one needs to be displayed and repeated one needs to be rejected.

    Thanks

    Sue

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    >If utctype equals to utctype of next record then the first one needs to be displayed and repeated one needs to be rejected.

    Rows in a table have no inherent order.
    Rows in a table are like balls in a basket.
    If you pick a ball out of the basket, which is ball in the basket in the "next" ball?

    Is this the same homework assignment?
    http://www.dbforums.com/oracle/16375...-record-b.html
    Last edited by anacedent; 01-27-09 at 22:58.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Mar 2008
    Posts
    89
    Well, for each "distinct" utcode, there are several utytype in your example,
    and you want to select the lowest one of them, right?

    Sounds to me like a "Select utccode, min(utytype) [...]" construction would be one possible way.

    Maybe along these lines:
    Code:
    Select a.utcode, a.uty, b.data 
    from (select utcode, min(utytype) as uty from mytable 
            group by utcode) A, 
           mytable B
    where a.utcode=b.utcode and a.uty=b.utytype;
    I haven't tried it though, so wouldn't lay my hand in any fires for it.
    "My brain is just no good at being a relational Database - my relations suck real bad!"

  4. #4
    Join Date
    Jan 2008
    Posts
    9
    It worked really well.. Thank you so much..

    Sue

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •