Internet, Networking, & Security Web Development 105 105 people found this article helpful Retrieving Data with SQL Queries: Introducing the SELECT Statement by Mike Chapple Writer Former Lifewire writer Mike Chapple is an IT professional with more than 10 years' experience cybersecurity and extensive knowledge of SQL and database management. our editorial process Twitter Mike Chapple Updated on November 13, 2019 Web Development SQL CSS & HTML Web Design Tweet Share Email The Structured Query Language offers database users a powerful and flexible data retrieval mechanism — the SELECT statement. In this article, we'll take a look at the general form of the SELECT statement and compose a few sample database queries together. If this is your first foray into the world of the Structured Query Language, you may wish to review SQL fundamentals before continuing. If you're looking to design a new database from scratch, learning how to create databases and tables in SQL should prove a good jumping-off point. Now that you've brushed up on the basics, let's begin our exploration of the SELECT statement. As with previous SQL lessons, we'll continue to use statements that are compliant with the ANSI SQL standard. You may wish to consult the documentation for your DBMS to determine whether it supports advanced options that may enhance the efficiency and/or efficacy of your SQL code. Getty Images/ermingut The General Form of the SELECT Statement The general form of the SELECT statement appears below: SELECT select_listFROM sourceWHERE condition(s)GROUP BY expressionHAVING conditionORDER BY expression The first line of the statement tells the SQL processor that this command is a SELECT statement and that we wish to retrieve information from a database. The select_list allows us to specify the type of information we wish to retrieve. The FROM clause in the second line specifies the specific database table(s) involved and the WHERE clause gives us the capability to limit the results to those records that meet the specified condition(s). The final three clauses represent advanced features outside the scope of this article – we'll explore them in future SQL articles. The easiest way to learn SQL is by example. With that in mind, let's begin looking at some database queries. Throughout this article, we'll use the employee's table from the fictional XYZ Corporation human resources database to illustrate all of our queries. Here's the entire table: EmployeeID LastName FirstName Salary ReportsTo 1 Smith John 32000 2 2 Scampi Sue 45000 NULL 3 Kendall Tom 29500 2 4 Jones Abraham 35000 2 5 Allen Bill 17250 4 6 Reynolds Allison 19500 4 7 Johnson Katie 21000 3 Retrieving an Entire Table XYZ Corporation's Director of Human Resources receives a monthly report providing salary and reporting information for each company employee. The generation of this report is an example of the SELECT statement's simplest form. It simply retrieves all of the information contained within a database table — every column and every row. Here's the query that will accomplish this result: SELECT * Pretty straightforward, right? The asterisk (*) appearing in the select_list is a wildcard used to inform the database that we would like to retrieve information from all of the columns in the employee's table identified in the FROM clause. We wanted to retrieve all of the information in the database, so it wasn't necessary to use a WHERE clause to restrict the rows selected from the table. Here's what our query results look like: EmployeeID LastName FirstName Salary ReportsTo ---------- -------- --------- ------ --------- 1 Smith John 32000 2 2 Scampi Sue 45000 NULL 3 Kendall Tom 29500 2 4 Jones Abraham 35000 2 5 Allen Bill 17250 4 6 Reynolds Allison 19500 4 7 Johnson Katie 21000 3 More from Lifewire What You Need to Know About Structured Query Language Creating Databases and Tables in SQL How to Count Database Table Values With SQL COUNT Pattern Matching in SQL Queries The Fundamentals of SQL Data Control Language (DCL) Microsoft Access GROUP BY Query What Is the Definition of a Database Query? Controlling Data Access With Views in SQL A Step-By-Step Guide to Using TRY/CATCH to Handle SQL Server Errors Access Controls for Users and Roles in SQL Structured Query Language Frequently Asked Questions Glossary of Common Database Terms Selecting Data Within Ranges in SQL What Is a Database? What Is Boyce-Codd Normal Form (BCNF)?