Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
07-03-2012, 03:41 PM #1
- Join Date
- Apr 2010
- 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
SELECT NAME, Country, NORMAL_STATE, CURRENT_STATE FROM SOMS_TABLE WHERE SOMS_TABLE.NAME LIKE 'AR%' ORDER BY SOMS_TABLE.Country ASC
07-03-2012, 04:10 PM #2
- Join Date
- Jun 2008
- New Jersey
- 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_STATEbefore 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.
07-03-2012, 08:38 PM #3
Keleth is correct. In other words:
Note: In MySQL you can use either != or <> and they mean the same thing.Code:SELECT NAME, Country, NORMAL_STATE, CURRENT_STATE FROM SOMS_TABLE WHERE NAME LIKE 'AR%' AND NORMAL_STATE != CURRENT_STATE ORDER BY Country ASC
Be yourself. No one else is as qualified.