select row depending on column value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ScarletPimpernal
    New Member
    • Mar 2007
    • 39

    select row depending on column value

    Hi Friends,

    Table
    -----

    ID -- FId -- FVal
    ------------------
    1 -- 15 -- 0
    2 -- 15 -- 1
    3 -- 16 -- 0
    4 -- 16 -- 0
    5 -- 17 -- 0
    6 -- 17 -- 1
    7 -- 17 -- 1

    From this table values i want to take the
    FId which has FVal =0 alone.

    How can i get it?

    Thanks,
    Pimp
  • Motoma
    Recognized Expert Specialist
    • Jan 2007
    • 3236

    #2
    Code:
    SELECT Fld FROM tableName WHERE FVal = 0


    Originally posted by ScarletPimperna l
    Hi Friends,

    Table
    -----

    ID -- FId -- FVal
    ------------------
    1 -- 15 -- 0
    2 -- 15 -- 1
    3 -- 16 -- 0
    4 -- 16 -- 0
    5 -- 17 -- 0
    6 -- 17 -- 1
    7 -- 17 -- 1

    From this table values i want to take the
    FId which has FVal =0 alone.

    How can i get it?

    Thanks,
    Pimp

    Comment

    • ScarletPimpernal
      New Member
      • Mar 2007
      • 39

      #3
      Actually i made a mistake in the question..

      I should have asked correctly..Its my mistake only

      Let me tell the question again

      ID -- FId -- FVal
      ------------------
      1 -- 15 -- 0
      2 -- 15 -- 1
      3 -- 16 -- 0
      4 -- 16 -- 0
      5 -- 17 -- 0
      6 -- 17 -- 1
      7 -- 17 -- 1

      I just need the values of FId which has only FVal =0

      For Example:

      I need the answer

      3 -- 16 -- 0
      4 -- 16 -- 0
      5 -- 17 -- 0

      Because FId 15 and 17 has FVal =0 and also FVal = 1
      But FId 16 only has FVal = 0..

      I think this is clear to you all now..

      help me in this.


      Thanks,
      Scarlet

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        It depends on the version of MySQL you are using, but something like this should work:

        Code:
        SELECT * FROM tableName WHERE fld IN
          (SELECT Fld FROM tableName GROUP BY Fld HAVING SUM(FVal) = 0)
        Originally posted by ScarletPimperna l
        Actually i made a mistake in the question..

        I should have asked correctly..Its my mistake only

        Let me tell the question again

        ID -- FId -- FVal
        ------------------
        1 -- 15 -- 0
        2 -- 15 -- 1
        3 -- 16 -- 0
        4 -- 16 -- 0
        5 -- 17 -- 0
        6 -- 17 -- 1
        7 -- 17 -- 1

        I just need the values of FId which has only FVal =0

        For Example:

        I need the answer

        3 -- 16 -- 0
        4 -- 16 -- 0
        5 -- 17 -- 0

        Because FId 15 and 17 has FVal =0 and also FVal = 1
        But FId 16 only has FVal = 0..

        I think this is clear to you all now..

        help me in this.


        Thanks,
        Scarlet

        Comment

        • ScarletPimpernal
          New Member
          • Mar 2007
          • 39

          #5
          Thanks Motaoma...




          Thanks,
          Scarlet

          Comment

          Working...