How To Software Retrieving Data with SQL Queries: Introducing the SELECT Statement Share Pin Email Print ermingut / Getty Images Software Databases Documents Spreadsheets Presentations Desktop Publishing Graphic Design Animation & Video by Mike Chapple An IT professional with more than 10 years of experience in the fields of databases and cybersecurity. Updated May 23, 2019 84 84 people found this article helpful 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. 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 *FROM employees 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 Continue Reading The Fundamental Guide to SQL Learn How Structured Query Language (SQL) Helps Talk to a Database An Easy Guide to Creating Databases and Tables in SQL Control Access Permission to Your Database Using DCL Learn How to Query Your Database How to Select Data Within Ranges in SQL Almost Every Web Page You Visit Has SQL Behind It SQL FAQ: Get Answers to Common Structured Query Language Questions How Do you Retrieve Data From Multiple Tables With SQL Joins? Database Terms You Need to Know The SQL COUNT Function Does Exactly What You Think: It Counts An Overview of Microsoft Access 2010 How Do You Use TRY...CATCH to Fix SQL Server Errors? 5 Things Beginners Need to Know About Databases Here's How to Create Foreign Keys in Microsoft SQL Server How Do You Control Data Access With Views?