Results 1 to 2 of 2

Thread: Oracle Find Minimum from temp table

  1. #1
    Join Date
    Sep 2006
    Posts
    2

    Oracle Find Minimum from temp table

    I have a select statement that returns a list of users ids and and a numberic value column we will call X. Each user can have one or many values for X. I need to do a secondary select from the temp table to get the least value for each useid for their value of X

    how does one do this in Oracle SQL

    example temp table
    userid X
    JJ 2
    RJ 5
    TL 3
    TL 7
    RJ 2
    JB 8

    I would want to get

    JJ 2
    RJ 2
    TL 3
    JB 8

    Thanks in advance

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Not sure what you want exactly, this will give you min value.

    select userid, min(x)
    from temp
    group by userid

    if you need to use it to get more data from temp then you can do

    select a.*
    from temp a
    join (
    select userid, min(x) x
    from temp
    group by userid) b
    on a.userid=b.userid and a.x=b.x

Posting Permissions

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