locked
How to exclude specific address unless if it's the only existing address RRS feed

  • Question

  • User869176912 posted

    Hi All,

    I'm doing a SELECT query to a table where the person can have dups each one having different addresses. I need to pick one to set as their main address but it cannot be a 'po box' (which is not a problem), the problem is, how can I include the 'po box' if it's the only address available for the person.

    Name UserID Address
    name1 userid1 po box1
    name1 userid1 111 addr st.
    name1 userid1 112 loc st.
    name2 userid2 po box2
    name3 userid3 311 loc st.
    name3 userid3 322 addr st.

    Expected output

    Name UserID Address
    name1 userid1 111 addr st.
    name2 userid2 po box2
    name3 userid3 311 loc st

    Wednesday, March 28, 2018 7:17 PM

All replies

  • User347430248 posted

    Hi Mike89.

    You had asked,"how can I include the 'po box' if it's the only address available for the person."

    You can try to fire 2 queries. one for getting main address and second for fetching data that only have po box as address.

    Then you can combine the result using Union.

    Reference:

    Set Operators - UNION (Transact-SQL)

    Regards

    Deepak

    Friday, March 30, 2018 9:24 AM