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 Scalar Subquery

    Overview

    In this tutorial, we will learn about Scalar Subquery with an example. Scalar subquery is the simplest form
    of a subquery. Scalar subquery as the name suggests is a subquery that returns a scalar or single value.

    To know the scalar subquery placement in the SQL statement:

    https://www.testingdocs.com/mysql-subquery-placement-chart/

    Example

    In this example, we will use the City table from the world MySQL table.  The following example shows how to use a scalar subquery as part of a WHERE clause conditions.

    mysql> SELECT Name FROM City
    -> WHERE Population >
    -> (SELECT Population FROM City WHERE Name= ‘New York’);
    +——————-+
    | Name |
    +——————-+
    | São Paulo |
    | Jakarta |
    | Mumbai (Bombay) |
    | Shanghai |
    | Seoul |
    | Ciudad de México |
    | Karachi |
    | Istanbul |
    | Moscow |
    +——————-+
    9 rows in set (0.03 sec)

     

    MySQL Scalar Subquery

    If we execute the subquery from the above example as a stand-alone statement, we will notice that the query yields a scalar/single value.

    mysql> SELECT Population FROM City WHERE Name= ‘New York’;
    +————+
    | Population |
    +————+
    | 8009000 |
    +————+
    1 row in set (0.00 sec)

    MySQL Scalar Subquery Example

    Scalar subqueries can appear almost anywhere that a scalar value is allowed by the SQL syntax.
    This means that you can use subqueries as function parameters, use mathematical operators on subqueries
    that evaluate to numeric values, etc.

    —

    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 Correlated Subquery› MySQL Subquery Placement

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com