Nested query  

  • Nested query:

    • A nested query is a SELECT query where the WHERE clause contains subquery.

  • Schematically:   what a nested query looks link

     Nested query:
    
       SELECT ...
       FROM   ...
       WHERE  ... (SELECT ...    /* Subquery */   
    	       FROM ... 
    	       WHERE ...)  
    

     

     

  How deep can you nest queries ?  

  • In theory, nesting can be arbitrarily deep:

       SELECT ...
       FROM   ...
       WHERE  ... (SELECT ... 
    	       FROM ... 
    	       WHERE ... (SELECT ...
    			  FROM ...
    			  WHERE ... ( ...
    			              ...
                                        )
                              )
                   )
    

  • In practice, depending on your DBMS system, the number of nesting levels is limited (and different for each system)

    • According to click here, MySQL can have 60 levels of nested selects.