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 clauseDescription
DISTINCTThis clause is used to eliminate duplicate rows from the result set.
FROMThis keyword is used to specify the database table(s) to retrieve data from the database.
WHEREThis 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.
LIMITThis 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

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

Windows 11 Services Run Prompt

MySQL /

Start MySQL Server on Windows 11

MySQL Download Windows 11

MySQL /

Download & Install MySQL on Windows 11

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

Recent Posts

  • Flowchart Control structures
  • Flowgorithm Layout Windows
  • Draw a Square using Turtle Graphics
  • Flowgorithm File Errors
  • Write to Text File using Flowgorithm
  • Read Text File using Flowgorithm
  • Flowgorithm Turtle Graphics Flowchart
  • Update Flowgorithm to Latest Version
  • Flowgorithm File Symbols
  • Flowgorithm Turtle Graphics

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version