Logical processing of a query

Hi,

I am working on a query and it is giving me different results although logic appears same 

here's it

USE db 

SELECT table1.table1id 
FROM   table1 
       INNER JOIN table2 
               ON table1.table2id = 
                  table2.table2id 
       INNER JOIN table3 
               ON table2.table3id = 
                  table3.table3id 
       INNER JOIN table4 
               ON table1.table4id = table4.table4id 
       INNER JOIN table5 
               ON table4.table5id = table5.table5id 
       INNER JOIN  table6 b 
              ON  b.table1id =  table1.table1ID
WHERE  ( table3.identifier1 = 'PP' ) 
       AND ( table5.identifier2  <> 'IIII' ) 


If I modify the same query and replace Inner Join -- Table6 with a query  like

USE db 

SELECT table1.table1id 
FROM   table1 
       INNER JOIN table2 
               ON table1.table2id = 
                  table2.table2id 
       INNER JOIN table3 
               ON table2.table3id = 
                  table3.table3id 
       INNER JOIN table4 
               ON table1.table4id = table4.table4id 
       INNER JOIN table5 
               ON table4.table5id = table5.table5id 
       
WHERE  ( table3.identifier1 = 'PP' ) 
       AND ( table5.identifier2  <> 'IIII' ) 

and    table1.table1id in 
(select table1id from table6 ) 

The <g class="gr_ gr_174 gr-alert gr_spell ContextualSpelling ins-del multiReplace" data-gr-id="174" id="174">rowcount</g> is different . The first query is returning more rows than second  .. 

but logically where clause and AND should be doing the same operation as inner join in first 

Please suggest

July 28th, 2015 3:07am

but logically where clause and AND should be doing the same operation as inner join in first 

Hello,

Not if there is a 1:n relation between table1 and table6, and table6 contains several equal entry in column "table1id"

Free Windows Admin Tool Kit Click here and download it now
July 28th, 2015 3:25am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics