none
SQL: Query to fetch column of having a specific value in entire group RRS feed

  • Question

  • Hi,

    I am learning SQL.

    I have a data table as below

    I need to get all Coumn A, for which all entries of column B is either 0 or 1.

    ColumnA      ColumnB

    1                  1

    2                  10

    2                  1

    3                 11

    3                10

    3                 1

    4                  1

    4                  0

    5                  1

    5                  1

    5                 1

    O/P:

    1                  

    4                  

    5

    I wrote query as below, but not getting the desired out put.

    can someone help me

    select ColumnA from DataTable where ColumnB =1 or ColumnB = 1

    • Moved by Bill_Stewart Monday, July 17, 2017 7:57 PM Off-topic
    Monday, July 17, 2017 5:44 PM

All replies

  • Sorry but this is not a SQL forum.  You will do better if you post in the correct forum.

    Here is an answer but post any other questions in a SQL forum.

    select ColumnA from DataTable where ColumnB =0 or ColumnB = 1

    Your query had "1" twice.  I recommend that you proofread your code carefully before asking a question.


    \_(ツ)_/

    Monday, July 17, 2017 5:52 PM