TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    MySQL

    MySQL Non-Correlated Subquery

    Overview

    In this tutorial, we will learn about MySQL Non-Correlated Subquery with example.

    Non-Correlated Subquery

    A non-correlated subquery contains no references to the outer query, is not dependent on it and can be evaluated as a completely separate SQL statement.

    Example

    In this example, we will use the world MySQL database and the City and the Country tables.

    City Table

    MySQL DESCRIBE City Table

    Country Table

    MySQL DESC Country Table

    This query uses a non-correlated subquery to list the names of all the cities in the City table
    that correspond with countries in the Country table that are part of the continent of ‘South America’.

    First, the inner query (subquery) finds all the country codes by continent. The outer query then selects the city names to go with each code in the City table. Since the subquery does not reference the City table (in the outer query), it is not a correlated subquery.

    mysql>SELECT Name FROM City WHERE CountryCode IN
    -> (SELECT Code FROM Country
    -> WHERE Continent= ‘South America’)

    MySQL Non-correlated Subquery

    Another aspect of this subquery that makes it non-correlated is that it can be run as a stand-along query:

    mysql>SELECT Code FROM Country
    ->WHERE Continent= ‘South America’;

    We can run the inner query itself of the non-correlated subquery (without the parenthesis) to see what it returns.

    —

    MySQL Tutorials

    MySQL Tutorials on this website:

    https://www.testingdocs.com/mysql-tutorials-for-beginners/

    For more information on MySQL Database:

    https://www.mysql.com/

    Related Posts

    Stellar Converter for Database Tool

    MySQL /

    Stellar Converter for Database

    Stellar MySQL Log Analyzer

    MySQL /

    Stellar Log Analyzer for MySQL

    Stellar Repair for MySQL

    MySQL /

    Stellar Repair for MySQL

    MySQL /

    How to secure your SQL Database: Tips and Tricks

    Stellar Converter for Database

    MySQL /

    Database Converter Tools

    ‹ MySQL Subquery Categories› MySQL Correlated Subquery

    Recent Posts

    • Running Tests in Parallel with Selenium Grid
    • Advanced Selenium Features
    • Locating Web Elements
    • Running the Test Script
    • Writing Your First Selenium Test Script
    • Getting Started with Selenium Automation Testing
    • Setting Up the Environment
    • How can you monitor the Quality Assurance Audit?
    • Leveraging LambdaTest with Appium 2.0
    • Appium 2.0 Plugins ListAppium 2.0 Plugins
    • Touch Actions and Multi-Touch Actions
    • Changes in Drivers and Classes
    • Appium Inspector
    • Capabilities in Appium 2.0
    • Appium 2.0 Driver ListAppium 2.0 Driver Installation & Management
    CyberLink Multimedia Software

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com