1

I have a table as below

INTERPRO    GOTERM1  GOTERM2   CONFIDENCE

IPR123      1576     2345       1.000
IPR235      3459     4987       1.000
IPR356      9987     5567       1.000
IPR568      3345     3213       0.88
IPR342      7860     7654       0.88 

Now I want any of the record with distinct confidence values only like below

IPR123   1576    2345   1.000
IPR342   7860    7654    0.88
2
  • 1
    Well, IPR123 1576 2345 1.000 and why not IPR235 3459 4987 1.000? Define additional criteria to decide which row to select. Commented Nov 13, 2010 at 7:03
  • any row with one distinct confidence value is taken .There is no particular criteria. Commented Nov 13, 2010 at 7:04

3 Answers 3

2

Using Sql Server 2005+ you can try something like

;WITH Vals AS(
        SELECT  *,
                ROW_NUMBER() OVER (PARTITION BY CONFIDENCE ORDER BY INTERPRO ) RowID
        FROM    YourTable
)
SELECT  *
FROM    Vals
WHERE   RowID = 1

ROW_NUMBER (Transact-SQL)

Sign up to request clarification or add additional context in comments.

Comments

0
SELECT t.INTERPRO, t.GOTERM1, t.GOTERM2, t.CONFIDENCE
FROM   tbl t
WHERE  t.INTERPRO = (SELECT MIN(t2.INTERPRO)
                     FROM   tbl t2
                     WHERE  t.CONFIDENCE = t2.CONFIDENCE)

Edit:

If INTERPRO is non-unique-per-CONFIDENCE:

SELECT t2.INTERPRO, t2.GOTERM1, t2.GOTERM2, t1.CONFIDENCE
FROM   (SELECT DISTINCT t3.CONFIDENCE FROM tbl t3) t1,
       (SELECT TOP 1 t4.INTERPRO, t4.GOTERM1, t4.GOTERM2
        FROM   tbl t4
        WHERE  t4.CONFIDENCE = t1.CONFIDENCE) t2

should work, though I don't have a SQL Server instance handy at the moment to double-check.

2 Comments

what if there are 2 rows with the same t.INTERPRO?
I thought of that after I posted and left the computer for the night. If INTERPRO is not unique per CONFIDENCE, then this wouldn't work, so time for an edit...
-1

if INTERPRO is unique

SELECT * FROM TABLE WHERE INTERPRO in 
(
SELECT MIN(INTERPRO) FROM TABLE
GROUP BY CONFIDENCE
)  

you can replace MIN() with anything you like

2 Comments

This query will give non-consistent data
as user489678 said : any row with one distinct confidence value is taken .There is no particular criteria.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.