---
description: SELECT SQL command is used for the later retrieval of stored data.It’s part of the data manipulation language that is responsible for query the data from the database.
title: MySQL SELECT Statement with Examples
image: https://www.guru99.com/images/mysql-select-statement.png
---

[Skip to content](#main)

**⚡ Smart Summary**

The MySQL SELECT statement retrieves rows from one or more tables, and every example below runs against the myflix sample database, moving from the plain star query to expressions, column aliases, and string functions.

- 🔎 **Core Purpose:** SELECT fetches stored rows that match a criteria, from the command prompt or from PHP, Python, and other languages.
- 🧩 **Syntax Order:** SELECT, FROM, WHERE, GROUP BY, HAVING, and ORDER BY must appear in that fixed sequence.
- ⭐ **Star Shortcut:** SELECT \* FROM \`members\`; returns every column, while naming columns explicitly keeps result sets smaller and faster.
- 🔗 **Expressions:** Concat() joins column values, and LEFT() trims characters, so computed fields appear directly in the result set.
- 🏷️ **Column Aliases:** The optional AS keyword renames any expression, replacing unreadable headers such as Concat(\`title\`) with clear labels.
- 🖱️ **Workbench Comparison:** MySQL Workbench generates queries visually, yet hand-written SELECT statements remain necessary for complex, precise retrieval.

Read More

![](https://www.guru99.com/images/mysql-select-statement.png)

## What is SELECT Query in MySQL?

**SELECT query** is used to fetch data from the MySQL database. Databases store data for later retrieval. The purpose of MySQL SELECT is to return one or more rows from the database tables that match a given criteria. A SELECT query can be used in a scripting language like PHP or Ruby, or you can execute it from the command prompt.

[![SELECT query in MySQL](https://www.guru99.com/images/select_confused.png)](https://www.guru99.com/images/select_confused.png)

Because SELECT is the command you will run most often, it pays to learn its syntax before touching the sample data.

## SQL SELECT Statement Syntax

SELECT is the most frequently used SQL command, and it has the following general syntax:

```
SELECT [DISTINCT|ALL] { * | [fieldExpression [AS newName]} FROM tableName [alias] [WHERE condition] [GROUP BY fieldName(s)] [HAVING condition] [ORDER BY fieldName(s)];
```

**HERE**

- **SELECT** is the SQL keyword that lets the database know that you want to retrieve data.
- **\[DISTINCT | ALL]** are optional keywords that fine-tune the results returned from the SQL SELECT statement. If nothing is specified, then ALL is assumed as the default.
- **{\*| \[fieldExpression \[AS newName]}** at least one part must be specified. “\*” selects all the fields from the specified table name; fieldExpression performs computations on the specified fields, such as adding numbers or joining two string fields into one.
- **FROM** tableName is mandatory and must contain at least one table. Multiple tables must be separated using commas or joined using the JOIN keyword.
- **WHERE** condition is optional. It specifies criteria in the result set returned from the query.
- **GROUP BY** is used to put together records that have the same field values.
- **HAVING** condition is used to specify criteria when working with the GROUP BY keyword.
- **ORDER BY** is used to specify the sort order of the result set.

\*

The star symbol selects all the columns in a table. A simple SELECT statement looks like the one shown below.

```
SELECT * FROM `members`;
```

The statement above selects all the fields from the members table. The semicolon is a statement terminator. It is not mandatory, but ending your statements this way is considered good practice.

## SELECT DISTINCT and LIMIT in MySQL

Two optional keywords in the syntax deserve a closer look, because beginners meet them as soon as a table grows.

**DISTINCT** removes duplicate rows from the result set. The movies table stores several films released in 2007, so a plain query repeats that year. DISTINCT returns each value once.

```
SELECT DISTINCT `year_released` FROM `movies`;
```

**LIMIT** caps the number of rows returned, which protects the client from a query that would otherwise pull millions of records.

```
SELECT * FROM `movies` LIMIT 5;
```

| Keyword | What it does | When to use it |
| --- | --- | --- |
| ALL (default) | Returns every matching row, duplicates included | Counting or listing raw records |
| DISTINCT | Collapses duplicate rows into one | Building a list of unique values |
| LIMIT | Returns only the first N rows | Previewing data or paging results |

With the syntax settled, the sample database brings these clauses to life.

## SELECT Statement Practical Examples

[**Click to download**](https://drive.google.com/uc?export=download&id=0B_vqvT0ovzHccjhtdGlrZ0MtZ0k) the myflix DB used for the practical examples.

You can learn how to import the .sql file into [MySQL Workbench](https://www.guru99.com/introduction-to-mysql-workbench.html).

The examples are performed on the following two tables.

Table 1: **members** table

| membership\_ number | full\_names | gender | date\_of\_ birth | physical\_ address | postal\_ address | contct\_ number | email |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | Janet Jones | Female | 21-07-1980 | First Street Plot No 4 | Private Bag | 0759 253 542 | janetjones@yagoo.cm |
| 2 | Janet Smith Jones | Female | 23-06-1980 | Melrose 123 | NULL | NULL | jj@fstreet.com |
| 3 | Robert Phil | Male | 12-07-1989 | 3rd Street 34 | NULL | 12345 | rm@tstreet.com |
| 4 | Gloria Williams | Female | 14-02-1984 | 2nd Street 23 | NULL | NULL | NULL |

Table 2: **movies** table

| movie\_id | title | director | year\_released | category\_id |
| --- | --- | --- | --- | --- |
| 1 | Pirates of the Caribean 4 | Rob Marshall | 2011 | 1 |
| 2 | Forgetting Sarah Marshal | Nicholas Stoller | 2008 | 2 |
| 3 | X-Men | NULL | 2008 | NULL |
| 4 | Code Name Black | Edgar Jimz | 2010 | NULL |
| 5 | Daddy’s Little Girls | NULL | 2007 | 8 |
| 6 | Angels and Demons | NULL | 2007 | 6 |
| 7 | Davinci Code | NULL | 2007 | 6 |
| 9 | Honey mooners | John Schultz | 2005 | 8 |
| 16 | 67% Guilty | NULL | 2012 | NULL |

**Don't Miss:**

- [MySQL Index: Create, Add & Drop Tutorial](https://www.guru99.com/indexes.html)
- [MySQL Regular Expressions (Regexp)](https://www.guru99.com/regular-expressions.html)
- [MySQL Workbench Tutorial: What is, How to Install & Use](https://www.guru99.com/introduction-to-mysql-workbench.html)
- [9 Best FREE SQL Courses with Certification (2026)](https://www.guru99.com/best-sql-certification-courses.html)

### Getting Members Listing

Suppose we want a list of all the registered library members from our database. We would use the script shown below to do that.

```
SELECT * FROM `members`;
```

Executing the script in MySQL Workbench produces the following results.

| membership\_ number | full\_names | gender | date\_of\_ birth | physical\_ address | postal\_ address | contct\_ number | email |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | Janet Jones | Female | 21-07-1980 | First Street Plot No 4 | Private Bag | 0759 253 542 | janetjones@yagoo.cm |
| 2 | Janet Smith Jones | Female | 23-06-1980 | Melrose 123 | NULL | NULL | jj@fstreet.com |
| 3 | Robert Phil | Male | 12-07-1989 | 3rd Street 34 | NULL | 12345 | rm@tstreet.com |
| 4 | Gloria Williams | Female | 14-02-1984 | 2nd Street 23 | NULL | NULL | NULL |

The query returned all the rows and columns from the members table.

### Selecting Specific Columns

Say we are interested only in the full\_names, gender, physical\_address, and email fields. The following script achieves this.

```
SELECT `full_names`,`gender`,`physical_address`, `email` FROM `members`;
```

Executing the script in MySQL Workbench produces the following results.

| full\_names | gender | physical\_address | email |
| --- | --- | --- | --- |
| Janet Jones | Female | First Street Plot No 4 | janetjones@yagoo.cm |
| Janet Smith Jones | Female | Melrose 123 | jj@fstreet.com |
| Robert Phil | Male | 3rd Street 34 | rm@tstreet.com |
| Gloria Williams | Female | 2nd Street 23 | NULL |

### Getting Movies Listing With Expressions

Expressions can also be used in SELECT statements. Say we want a list of movies with the title and the name of the director in one field, the director in brackets, plus the year the movie was released. The following script does that.

```
SELECT Concat(`title`, ' (', `director`, ')') , `year_released` FROM `movies`;
```

**HERE**

- The Concat() MySQL function joins column values together.
- The line “Concat(\`title\`, ‘ (‘, \`director\`, ‘)’)” gets the title, adds an opening bracket followed by the name of the director, then adds the closing bracket.
- String portions are separated using commas inside the Concat() function.

Executing the script in MySQL Workbench produces the following result set.

| Concat(\`title\`, ‘ (‘, \`director\`, ‘)’) | year\_released |
| --- | --- |
| Pirates of the Caribean 4 ( Rob Marshall) | 2011 |
| Forgetting Sarah Marshal (Nicholas Stoller) | 2008 |
| NULL | 2008 |
| Code Name Black (Edgar Jimz) | 2010 |
| NULL | 2007 |
| NULL | 2007 |
| NULL | 2007 |
| Honey mooners (John Schultz) | 2005 |
| NULL | 2012 |

**Note:** Concat() returns NULL when any argument is NULL, which is why films without a director show NULL above.

### Alias Field Names

The example above returned the concatenation code as the field name. To use a more descriptive field name in the result set, apply a column alias. The basic syntax follows.

```
SELECT `column_name|value|expression` [AS] `alias_name`;
```

**HERE**

- **“SELECT \`column\_name|value|expression\`”** is the regular SELECT statement, which can be a column name, value, or expression.
- **“\[AS]”** is the optional keyword before the alias name.
- **“\`alias\_name\`”** is the alias that is returned in the result set as the field name.

The same query with a more meaningful column name:

```
SELECT Concat(`title`, ' (', `director`, ')') AS `Concat`, `year_released` FROM `movies`;
```

We get the following result.

| Concat | year\_released |
| --- | --- |
| Pirates of the Caribean 4 ( Rob Marshall) | 2011 |
| Forgetting Sarah Marshal (Nicholas Stoller) | 2008 |
| NULL | 2008 |
| Code Name Black (Edgar Jimz) | 2010 |
| NULL | 2007 |
| NULL | 2007 |
| NULL | 2007 |
| Honey mooners (John Schultz) | 2005 |
| NULL | 2012 |

### Getting Members Listing Showing the Year of Birth

Suppose we want a list of all members showing the membership number, full names, and year of birth. We can use the LEFT string function to extract the year of birth from the date of birth field.

```
SELECT `membership_number`,`full_names`,LEFT(`date_of_birth`,4) AS `year_of_birth` FROM members;
```

**HERE**

- **“LEFT(\`date\_of\_birth\`,4)”** the **LEFT string function** accepts the date of birth as the parameter and returns only 4 characters from the left.
- **“AS \`year\_of\_birth\`”** is the **column alias name** returned in our results. The **AS keyword is optional**; you can leave it out and the query still works.

Executing the query in MySQL Workbench against the myflixdb gives us the results shown below.

| membership\_number | full\_names | year\_of\_birth |
| --- | --- | --- |
| 1 | Janet Jones | 1980 |
| 2 | Janet Smith Jones | 1980 |
| 3 | Robert Phil | 1989 |
| 4 | Gloria Williams | 1984 |

Hand-written queries are only one route to a result set. Workbench can also build the statement for you.

## SQL Using MySQL Workbench

We are now going to use MySQL Workbench to generate the script that displays all the field names from our categories table.

1\. Right-click on the Categories table. Click on “Select Rows – Limit 1000”.

2\. MySQL Workbench automatically creates a SQL query and pastes it in the editor.

3\. Query results are shown in the grid below the editor.

[![SQL using MySQL Workbench]()](https://www.guru99.com/images/SelectMySQLWorkBench.png)

As the screenshot shows, we did not write the SELECT statement ourselves. MySQL Workbench generated it for us.

## Why Use the SELECT SQL Command When We Have MySQL Workbench?

You might be wondering why you should learn the SQL SELECT command when a tool such as MySQL Workbench returns the same results without any knowledge of the SQL language. That shortcut is possible, but **learning the SELECT command** gives you more **flexibility** and **control** over your **SQL SELECT statements**.

MySQL Workbench falls into the category of “**Query by Example**” (QBE) tools. It is intended to generate SQL statements faster and increase user productivity.

Learning the SQL SELECT command lets you create **complex queries** that cannot easily be generated by Query by Example utilities such as MySQL Workbench.

To improve productivity, you can **generate the code in MySQL Workbench**, then **customize** it to **meet your requirements**. That is only possible once you understand how the SQL statements work.

![Understanding the MySQL SELECT statement]()

## FAQs

⚡ Is SELECT \* slower than naming the columns?

Usually yes. SELECT \* reads every column, including large text and blob fields you may not need, and it blocks covering indexes. Naming the columns keeps the result set smaller and the query faster.

🔤 Are MySQL SELECT queries case sensitive?

Keywords such as SELECT and FROM are not case sensitive. String comparisons follow the collation of the column, so a case-insensitive collation such as utf8mb4\_0900\_ai\_ci treats “Janet” and “janet” as equal.

🐢 Why is my SELECT query running slowly?

A missing index is the usual cause. Run EXPLAIN before the query to see whether MySQL performs a full table scan, then index the filtered or joined columns and return only the rows you need.

🤖 Can AI write MySQL SELECT queries from plain English?

Yes. Text-to-SQL assistants convert a plain request into a SELECT statement once they know your schema. Review the generated joins and filters, because an AI model can invent column names that do not exist.

🧠 Does AI replace the need to learn SELECT?

No. AI drafts a query quickly, but you still verify the logic, the joins, and the performance in [MySQL Workbench](https://www.guru99.com/introduction-to-mysql-workbench.html). Knowing SELECT is what lets you spot a wrong result before it reaches production.

#### Summarize this post with:

ChatGPTPerplexityGrokGoogle AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/mysql-select-statement.png","url":"https://www.guru99.com/images/mysql-select-statement.png","width":"700","height":"250","caption":"MySQL SELECT Statement","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/select-statement.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/sql","name":"SQL"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/select-statement.html","name":"MySQL SELECT Statement with Examples"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/select-statement.html#webpage","url":"https://www.guru99.com/select-statement.html","name":"MySQL SELECT Statement with Examples","dateModified":"2026-10-07T16:13:30+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/mysql-select-statement.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/select-statement.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"SQL","headline":"MySQL SELECT Statement with Examples","description":"SELECT SQL command is used for the later retrieval of stored data.It\u2019s part of the data manipulation language that is responsible for query the data from the database.","keywords":"sql","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-07T16:13:30+05:30","image":{"@id":"https://www.guru99.com/images/mysql-select-statement.png"},"copyrightYear":"2026","name":"MySQL SELECT Statement with Examples","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Is SELECT * slower than naming the columns?","acceptedAnswer":{"@type":"Answer","text":"Usually yes. SELECT * reads every column, including large text and blob fields you may not need, and it blocks covering indexes. Naming the columns keeps the result set smaller and the query faster."}},{"@type":"Question","name":"Are MySQL SELECT queries case sensitive?","acceptedAnswer":{"@type":"Answer","text":"Keywords such as SELECT and FROM are not case sensitive. String comparisons follow the collation of the column, so a case-insensitive collation such as utf8mb4_0900_ai_ci treats \"Janet\" and \"janet\" as equal."}},{"@type":"Question","name":"Why is my SELECT query running slowly?","acceptedAnswer":{"@type":"Answer","text":"A missing index is the usual cause. Run EXPLAIN before the query to see whether MySQL performs a full table scan, then index the filtered or joined columns and return only the rows you need."}},{"@type":"Question","name":"Can AI write MySQL SELECT queries from plain English?","acceptedAnswer":{"@type":"Answer","text":"Yes. Text-to-SQL assistants convert a plain request into a SELECT statement once they know your schema. Review the generated joins and filters, because an AI model can invent column names that do not exist."}},{"@type":"Question","name":"Does AI replace the need to learn SELECT?","acceptedAnswer":{"@type":"Answer","text":"No. AI drafts a query quickly, but you still verify the logic, the joins, and the performance in MySQL Workbench. Knowing SELECT is what lets you spot a wrong result before it reaches production."}}]}],"@id":"https://www.guru99.com/select-statement.html#schema-1143841","isPartOf":{"@id":"https://www.guru99.com/select-statement.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/select-statement.html#webpage"}}]}
```
