faqts : Computers : Databases : MySQL : Language and Syntax : Queries

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

2 of 2 people (100%) answered Yes
Recently 2 of 2 people (100%) answered Yes

Entry

How do you compare two text fields to see they are not equal. (part_desc <> model_name)??????

Mar 15th, 2004 10:19
Matt Chatterley, Bob Ryan,


If you are purely interested in strict equality, you can use the !=
operator e.g:
SELECT * FROM Table1 WHERE part_desc != model_name;
This will not work if they are CHAR (as opposed to VARCHAR) columns of
different length - since one will contain more spaces than the other.
This is alleviated if you were to do:
SELECT * FROM Table1 WHERE TRIM(BOTH ' ' FROM part_desc) != TRIM(BOTH '
' FROM model_name);
Additionally, this is case sensitive. If you wish to do a case
IN-sensitive comparison, you could wrap the columns in the LOWER() or
UPPER() function to force data for comparison into a given case.