Tutorials – Using MySQL SELECT Statement to Query Data

mysql-select-2

Summary: in this tutorial, you will learn how to MySQL SELECT statement to query data from a database table.

The MySQL SELECT statement allows you to retrieve zero or more rows from database tables or database views. MySQL SELECT statement is the most commonly used query in MySQL. The MySQL SELECT statement returns a result, which is also known as a result set.

MySQL SELECT syntax

The following illustrates the syntax of the SELECT statement:

1
2
3
4
5
6
7
8
SELECT column_1,column_2...
FROM table_1
[INNER | LEFT |RIGHT] JOIN table_2 ON conditions
WHERE conditions
GROUP BY group
HAVING group_conditions
ORDER BY column_1 [ASC | DESC]
LIMIT offset, row_count

The SELECT statement has many clauses as follows:

You will learn each clause in more detail in the next tutorial. In this tutorial, we are going to focus on the simple form of the SELECT statement.

MySQL SELECT Examples

To select all columns and rows in the employees table, you use the following query:

1
SELECT * FROM employees

mysql-select

The asterisk (*) notation selects all columns in the table.

The SELECT statement also allows you to select partial data of a table by specifying a list of comma-separated columns in the SELECT clause. For example, if you want to view only first name, last name and job title of the employees,  you use the following query:

1
2
3
4
SELECT lastname,
       firstname,
       jobtitle
FROM employees

mysql-select-2

In this tutorial, you’ve learned about the basic MySQL SELECT statement to query data from one database table.

From http://www.mysqltutorial.org/