DBAsupport.com Forums - Powered by vBulletin
Results 1 to 5 of 5

Thread: sql query

  1. #1
    Join Date
    Feb 2001
    Posts
    34
    Hi,
    I'm trying to write a query which pulls the distinct records from a table.
    I've a table which has a primary key column(ID). One more significant field is move_id.Except the PK field all other fields are duplicated for some rows. But for each distinct move_id I've couple of rows with different PK values. But from which I want only one(any one).

    Table Test:
    ID move_id name ....
    1 'xx' 'pp'
    2 'xx' 'pp'
    3 'xx' 'pp'
    4 'yy' 'uu'
    5 'yy' 'uu'

    I'm trying to write a query which gives me

    1 'xx' 'pp'
    2 'yy' 'uu'
    ....

    Thanks,
    kkr

  2. #2
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    use rank function,
    this may help U.

    SELECT ename, sal
    FROM
    ( SELECT ename, sal, RANK() OVER (ORDER BY sal DESC) as rank
    FROM emp
    )
    WHERE rank <= 5;
    rgds,
    Cheers!
    OraKid.

  3. #3
    Join Date
    Dec 2001
    Location
    Bangalore, India
    Posts
    23

    Smile

    Hi KKR,

    You can use the following queries.

    select * from where rowid in
    (select max(rowid) from group by move_id)

    or

    select * from where rowid in
    (select min(rowid) from group by move_id)

    Hope this will help you.
    Regards,
    Vijay R.

  4. #4
    Join Date
    Mar 2001
    Location
    Reading, U.K
    Posts
    598
    hi vijay
    goodone
    Cheers!
    OraKid.

  5. #5
    Join Date
    Feb 2001
    Posts
    34
    It works. Thanks everyone.

Posting Permissions

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


Click Here to Expand Forum to Full Width