Home > Queries from Visitors > Mysql representing ‘not equal to’ in query

Mysql representing ‘not equal to’ in query

April 21st, 2009 Leave a comment Go to comments

Query
please help me to find out a solution for this am not getting correct o/p for query where am using mysql not equalto as (where tableone.file_name!=tabletwo.file_name)
Explanation
Though for conditional statements ‘!=’ or ‘<>’ can be used in queries, the real solution depends on what exactly one needs to achieve.

mysql> select logId,logDate from weblogs limit 2;
+-------+---------------------+
| logId | logDate             |
+-------+---------------------+
|     1 | 2008-11-02 08:02:53 | 
|     2 | 2008-11-02 08:02:54 | 
+-------+---------------------+
2 rows in set (0.00 sec)

mysql> select logId,logDate from weblogs where logId <> 2 limit 2;
+-------+---------------------+
| logId | logDate             |
+-------+---------------------+
|     1 | 2008-11-02 08:02:53 | 
|     3 | 2008-11-02 08:02:54 | 
+-------+---------------------+
2 rows in set (0.00 sec)

mysql> select logId,logDate from weblogs where logId != 2 limit 2;
+-------+---------------------+
| logId | logDate             |
+-------+---------------------+
|     1 | 2008-11-02 08:02:53 | 
|     3 | 2008-11-02 08:02:54 | 
+-------+---------------------+
2 rows in set (0.00 sec)

But when joining two tables, and to identify those rows where there is no matching corresponding fields, the query is different, and is explained neatly with examples in article MySQL joins – using left join and right join to find orphan rows at wellho.net.

Categories: Queries from Visitors Tags:
  1. No comments yet.
  1. No trackbacks yet.

three + three =