0

I am a novice Microsoft Query user. I have a table with info like

ckno    ckdate    type  
123     12/1/12     PV  
654     11/6/12     EP
123     12/14/12    EP
852     01/3/13     PV 

I want to return all the rows with a type of PV or EP where the ck# are the same (rows 1 and 3). What does the sql look like for this.

1

2 Answers 2

1

You can try this, which should allow you to have multiple differences in type:

    SELECT *
    FROM SomeTable t
    WHERE EXISTS 
        (SELECT 1 FROM SomeTable x 
        WHERE x.ckno = t.ckno AND x.type <> t.type)
Sign up to request clarification or add additional context in comments.

1 Comment

I should point out that if [type] can be NULL, then you'd want to be sure to handle that as well (ISNULL around your x.type and t.type is presumably the best way).
0
SELECT *
FROM YourTable T
WHERE EXISTS (  SELECT ckno 
                FROM YourTable
                WHERE [type] IN ('PV','EP')
                AND ckno = T.ckno
                GROUP BY ckno
                HAVING COUNT(*)>1)

Comments

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.