Home Forums SQL Server 2008 T-SQL (SS2K8) SQL Queries for geting common values and uncommon values RE: SQL Queries for geting common values and uncommon values

  • sankar.nandakumaran (3/15/2013)


    Hi......

    I have one table in my database say for example "TableA" and the data is shown below..

    ID Value

    1 A (common for all ids)

    1 B (common for all ids)

    2 A (common for all ids)

    2 C

    2 B (common for all ids)

    3 A (common for all ids)

    3 B (common for all ids)

    3 C

    3 D

    My problem is i need two sql queries which will give the following two resultant sets as shown below

    First sql query result will be like this Common Factors in ID (1,2,3)

    A

    B

    Second query result will be Common Factors in ID (1,2,3)

    C (here c is not in id 1 so will be listed here)

    D

    Can any one please give the two queries please , just i need common factors in one set and uncommon factors in another set ..I need two SQL queries but

    Thanks and Regards

    Sankar

    I will help you but first you have to enable me to help. There is no chance anybody can provide you with queries based on the extremely vague description posted. Please provide ddl (create table scripts), sample data (insert statements) and desired output based on your sample data. See the first link in my signature for best practices when posting questions.

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/