Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-03-2012, 03:41 PM   PM User | #1
zit1343
New to the CF scene

 
Join Date: Apr 2010
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
zit1343 is an unknown quantity at this point
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
zit1343 is offline   Reply With Quote
Old 07-03-2012, 04:10 PM   PM User | #2
Keleth
Senior Coder

 
Join Date: Jun 2008
Location: New Jersey
Posts: 2,354
Thanks: 45
Thanked 247 Times in 244 Posts
Keleth is on a distinguished road
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.
Keleth is offline   Reply With Quote
Old 07-03-2012, 08:38 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,248
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Tags
sql, sql database, sql select

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:06 PM.


Advertisement
Log in to turn off these ads.