Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing fields in two tables.

Status
Not open for further replies.

karnaf

Programmer
Nov 16, 2002
41
IL
Let's assume I'm trying to do something like

SELECT table1.field1, table1.field2, table2.field1 FROM table1, table2 WHERE (table1.field2 != table2.field1)

where table1.field2 and table2.field1 are both strings.

3 questions -
a. do I use the '!=' for not-equal or the '<>' ? (Which is the correct syntax in MySQL...)
b. can I do that when the fields I'm comparing are not of the same type (one is text or tinytext and the other is varchar)?
c. since I'm comparing strings here, can I do it case-insensitive?

Thanks.
 
a - mysql supports both != and <> as &quot;not equal&quot; operator
b - i think that should work
c - try this &quot;WHERE LCASE(table1.field2) != LCASE(table2.field1)&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top