February 6th, 2009

INNER JOIN with Non-Equal Conditions

Posted by admin in L. JOINs

You can use WHERE clause conditions other than = using <, <=, >, >=, <>, NOT column =, NOT NULL, LIKE, BETWEEN, IN, etc.

                       JOIN syntax:                                                   WHERE syntax:

          SELECT t1.column1 AS ‘title1′,                       SELECT t1.column1 AS ‘title1′,
                       t2.column2 AS ‘title2′, …                                 t2.column2 AS ‘title2′, …
             FROM table1        [AS] ‘t1′                              FROM table1         [AS] ‘t1′,
     INNER JOIN table2       [AS] ‘t2′                                        table2         [AS] ‘t2′
                  ON t1.column1 oper t2.column1[,          WHERE t1.column1 oper t2.column1[,
          AND|OR t1.column2 oper t2.column2]          AND|OR t1.column2 oper t2.column2];
           WHERE condition1
         [AND|OR condition2];

Where oper is a comparison operation and where is used for additional filtering.

Comments are closed.

Sorry, the comment form is closed at this time.