Structured Query Language (SQL) is the standard programming language used to communicate with relational databases. Because data usage in business is growing at a staggering rate, the demand for people who understand SQL, relational databases, and data management is rising.

The American National Standards Institute establishes SQL as a standard for relational database management, so programmers and administrators can learn just one single language that works with only minor adjustments across a wide variety of database platforms, applications, and products. If you’re looking to build a career in programming or database management or if you’d like to better understand the workings of your website or company databases, SQL is an important language to learn.

The Complete SQL Bootcamp 2021: Go from Zero to Hero

Last Updated May 2021

Bestseller
  • 83 lectures
  • All Levels
4.7 (109,542)

Become an expert at SQL! | By Jose Portilla

Explore Course

SQL is a language with a syntax all its own, consisting of statements, clauses, and other pieces of code such as operators that establish parameters for limiting the query. An SQL statement is a complete piece of code that goes to a database management system, or DBMS, in order to perform a variety of functions on data contained in the database. You can request specific information from the database by writing a query, which is a statement that returns or delivers the information you want from the tables within the database. The SELECT statement is the most common operation in SQL, as it specifies which data to return from the database.

The SELECT Statement and Its Significance

SELECT statements are frequently called Data Query Language (DQL) in SQL. In relational databases, you store data in table form — under columns and rows defined by the user — and those tables populate with the INSERT statement. The SELECT command operates with the FROM clause to retrieve or extract information from database tables and present it in an organized and readable way.

Binary, Hands, Keyboard, Tap, Enter, Input, Store, One

The SELECT keyword in the query states which rows and columns you want to display as the result set of a query. Using the SELECT statement, you can specify the values that match the rows in the table that you want the query to return.

In its simplest form, the SELECT statement must contain the following elements:

a SELECT clause that specifies the columns containing the values matching the query, and a FROM clause that specifies the TABLE containing the columns listed in the SELECT clause.

The SELECT statement can also have many optional clauses that refine the query and return precise results. Commonly used clauses include:

The basic syntax for a SELECT statement looks like this:

SELECT [column 1, column 2, ...] FROM source_table;

To display all the columns from a table in the result set, use the symbol “*” after SELECT.

Combining SQL SELECT and INSERT Statements

The INSERT statement containing a nested SELECT statement allows you to quickly populate a table with one or more rows from the result set of the SELECT command. You can insert multiple records in this way, like this:

INSERT INTO table (column1, column2, ... ) SELECT expression1, expression2, ... FROM source_tables WHERE conditions;

The syntax of this statement contains several parameters:

That means “column1” will have the value of “expression1”, “column2” will have the value of “expression2,” and so on. The ellipsis, or triple dots, after each of these elements indicates that the operation will apply to other columns and expressions in the series:

The SQL SELECT INTO Statement

The SELECT INTO statement selects data from one table and inserts it into a new table. You can choose one or more columns, or all columns, to copy into the new table. If you want to copy all columns, use the “*” after the SELECT statement. The syntax for this statement looks like this:

SELECT * INTO newtable [IN externaldb] FROM table1

The syntax in this statement includes four parameters.

SELECT* INTO selects all the columns in the first table

Here’s an example of an SQL SELECT INTO statement that creates a copy of an entire table of Vendors:

SELECT * INTO Vendorcopy2014 FROM Vendors;

But if we want to copy only specific columns into the new table, we’ll enter:

SELECT [column 1, column 3, ….] INTO newtable FROM table1;

This statement will generate a completely new table with the column names and types defined in the SELECT operator. For example, suppose we want to copy only the columns “Vendor Name” and “Country Name” into the new table. That statement looks like this:

SELECT VendorName, CountryName INTO Vendorcopy2014 FROM Vendors;

The SQL SELECT DISTINCT Statement

The DISTINCT clause is used in a SELECT statement to remove duplicates from the result set of the query. Here is the syntax for this statement:

SELECT DISTINCT expressions FROM tables WHERE conditions;

This statement includes these parameters:

If you don’t want to remove duplicate data, or if you’re sure that there will be no duplicates in the result set, then you can use ALL instead of DISTINCT. But ALL is the default keyword in SQL statements, so we usually omit it from query statements.

Conclusion

This tutorial provides an overview of the SQL SELECT statement and related clauses, but there’s so much more to explore. Take a look at our blog that highlights the most useful SQL commands to learn how to write basic SQL queries and other code statements. As you develop the knowledge and skills to become a database administrator and development, you’ll need to begin writing customized SQL code in order to meet the requirements of users as efficiently as possible.

If you want another in-depth look at another one of SQL’s most important operators, let’s progress to the INSERT INTO command.

Top courses in SQL

Microsoft SQL for Beginners
Mubashir Hassan | worldwide 80000+ enrollments
4.6 (53)
New
The SQL Programming Essentials 2021 Immersive Training
SDE OCTOPUS, Ahmed Ibrahim
4.5 (40)
New
Learn SQL +Security(pen) testing from Scratch
Rahul Shetty
4.5 (1,803)
Bestseller
SQL Programming Basics
Global Academy
4.5 (549)
The Complete SQL Bootcamp 2021: Go from Zero to Hero
Jose Portilla
4.7 (109,542)
Bestseller
The Ultimate MySQL Bootcamp: Go from SQL Beginner to Expert
Colt Steele, Ian Schoonover
4.6 (58,918)
Bestseller
Master SQL For Data Science
Imtiaz Ahmad
4.7 (8,394)
SQL for Beginners: Learn SQL using MySQL and Database Design
Tim Buchalka's Learn Programming Academy, Jon Avis - SQL Instructor
4.5 (15,686)

More SQL Courses

SQL students also learn

Empower your team. Lead the industry.

Get a subscription to a library of online courses and digital learning tools for your organization with Udemy for Business.

Request a demo