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 SELECT Statement

    Overview

    In this tutorial, we will learn MySQL SELECT statement with examples. The SELECT statement is used to retrieve data from the MySQL database.

    SELECT Statement

    The SELECT is the most commonly used statement. It is a DML statement.(Data Manipulation Language). The SELECT statement is the description of data that is retrieved from the MySQL database server. The response result( often called as the result set) returned by the server takes the form of table.

    The basic syntax of the of the statement:

    mysql> SELECT [options] column_list / expressions

                  [FROM table_name(s)]  [ clauses] ;

     

    The column_list is the list of columns names that will appear in the query result. We can specify multiple columns in the SELECT query. To retrieve all the columns of the table we can use the * symbol in the SQL query.

    Some clauses that can be specified in the SELECT statement are as follows:

    SELECT clause Description
    DISTINCT This clause is used to eliminate duplicate rows from the result set.
    FROM This keyword is used to specify the database table(s) to retrieve data from the database.
    WHERE This clause is used to filter specific rows from the result set.
    ORDER BY
    This clause is used to sort rows by specific order For example, ascending or descending.
    LIMIT This clause limits the maximum number of rows form the result set.

     

    The clauses are added to modify the results of the query in some form. For example, WHERE clause to restrict or filter the rows. The GROUP BY clause to group the data, etc.

    We can also format the SELECT query into multiple lines. This will increase the readability of the query.

    For example,

    SELECT [DISTINCT] columns_in_result
    FROM table_name(s)
    WHERE condition(s)
    ORDER BY column_name  sort_order
    LIMIT row_count;

    Examples

    Select all columns and rows

    To retrieve all the rows and columns of the department table. The * means all the columns.

    mysql> SELECT * FROM department;

    Select multiple columns

    We can specify the columns in the result. We can specify multiple columns with comma as separator in the SELECT statement. For example, to retrieve Name and Capital columns in the Country table from the world MySQL database.

    mysql> SELECT Name, Capital FROM Country;

    The result set will contain the columns specified in the query.

     

    MySQL SELECT Statement

     

    —

    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

    ‹ Import Data Using MySQLImport Utility› MySQL SELECT ORDER BY clause

    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