Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Apr 2010
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sql filter command only if column value not equal

    I have SQL command it currently shows
    1.Name (Person'e name) I only want that starts with AR
    2.Country (ANY COUNTRY) But sort them ASC A to Z
    3.Normal_State (this is given in Binary) Most of them 3 & 4 are equal
    4.Current_State (this is also given in Binary) Only want to if they are not equal

    1 and 2 I got it to work, I need help getting 3 and 4 for example



    Code:
    SELECT
     NAME, 
    Country, 
    NORMAL_STATE, 
    CURRENT_STATE 
    FROM SOMS_TABLE 
    WHERE SOMS_TABLE.NAME LIKE 'AR%' 
    ORDER BY SOMS_TABLE.Country ASC
    for example for image below I only want red one's to show up Thanks

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,535
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Not sure what you mean by "Most of them 3 & 4 are equal" and "Only want to if they are not equal"... these seem to be contradictory statements.

    It seems you want the latter, so you'd want to add AND NORMAL_STATE != CURRENT_STATE before the ORDER BY.

    Since you only have one table, you don't need the table reference before the folumn in the WHERE and order by columns.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,023
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Keleth is correct. In other words:
    Code:
    SELECT  NAME, Country, NORMAL_STATE, CURRENT_STATE 
    FROM SOMS_TABLE 
    WHERE NAME LIKE 'AR%' 
    AND NORMAL_STATE != CURRENT_STATE
    ORDER BY Country ASC
    Note: In MySQL you can use either != or <> and they mean the same thing.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •