• TestingDocs
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

MySQL /

How to secure your SQL Database: Tips and Tricks

DataGrip Desktop Shortcut

MySQL /

Launch DataGrip on Windows

DataGrip Download

MySQL /

Install DataGrip IDE on Windows 11

MySQL Workbench Windows 11

MySQL /

New MySQL Connection in Workbench

MySQL Command-line Client

MySQL /

Command-Line MySQL Client

‹ MySQL Subquery Categories› MySQL Correlated Subquery

Recent Posts

  • How to secure your SQL Database: Tips and Tricks
  • Shaping the Future of Development: Exploring Key Trends in Software Engineering
  • Improving Java Performance with Multithreading
  • Difference between PHP and JavaScript?
  • Bing Conversation Styles
  • ChatGPT Introduction
  • Open Source AI Frameworks
  • Artificial Intelligence Tools
  • Top AI Music Applications
  • Top AI Website Design Tools

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com