Sybase SQL Query pull single record if individual has multiple records with different data in one table

Posted on 2007-08-02
Last Modified: 2010-05-18
Hello Experts, I am creating a SQL query in Crystal Reports to run against a Sybase db. The data is information about individuals. The Address table contains Street addresses, both business and residential, with a column that contains an identifier(BUS, RES). I need to be able to pull all the unique individuals without getting both addresses. In other words, if an individual has just a RES address he needs to be pulled and if an individual has both types of addresses, I want to pull the business address only, and if Business only, pulled also.
Question by:JohnPell
    1 Comment
    LVL 10

    Accepted Solution


    You can do it with a GROUP BY HAVING:

    create table addresses (id int, type char(3))
    insert addresses values (1, "BUS")
    insert addresses values (2, "BUS")
    insert addresses values (2, "RES")
    insert addresses values (3, "RES")
    select id, type from addresses group by id having type = min(type)

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Database tuning – How to start and what to tune. This question is frequently asked by many people, both online and offline. There is no hard and fast rule-of-thumb for performance tuning, however, before beginning the tuning process one should a…
    I guess that all of us know that caching the data usually increase the performance, but I worried if all of us are aware about the risk that caching the data provides and how to minimize this.  That’s the reason why I decided to write this short art…
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now