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

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

Start MySQL Client

MySQL /

Start MySQL Client on Windows 11

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

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version