How to get DISTINCT rows with a twist

  • Column1 has a code and in column2, it's the description of the code. See attached file.

    I am joining this table with one more table by the code (column1) and pulling the description from column2. There are multiple entries of the same code and description. So I did the DISTINCT statement and came across one more problem.

    Here's the problem, there are multiple entries of Column2 which includes just extra '-I/P'or '-O/P', but have the same code (column1). If I do a join like this, I think SQL will freak out. I could delete rows with '-I/P'or '-O/P', but sometimes there is one entry which has either '-I/P'or '-O/P'.

    So here's what I am trying to do. First do a distinct statement. Then, I wanna check if code (column1) value\ exist more than one, and if they do, then delete the row which has '-I/P'or '-O/P' in column2.

    Any ideas?

    ------------
    🙂

  • check out the nice art :http://www.sqlservercentral.com/columnists/chawkins/dedupingdatainsqlserver2005.asp

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply