How to use SQL SELECT

SQL SELECT is a keyword and statement for selecting, retrieving and displaying data in columns and tables. It serves as the foundation for the majority of queries and actions in SQL, making it one of the most important tools in the language.

What is SQL SELECT?

The bigger the database, the more difficult it is to retrieve relevant information and records. That’s why SELECT is of the most important tools in SQL for efficient queries and statements. SQL SELECT specifies which records and columns you want to find, display and edit.

When combined with other SQL commands, SQL operators and SQL functions, SELECT can perform comparisons, calculations and pattern-based searches. For example, SQL SELECT DISTINCT delivers results without duplicates. SQL SELECT INTO copies data from an existing table into a new one. And SQL SELECT TOP limits the number of results.

Tip

Learn the basics of SQL and get started with this popular database language. Our SQL introduction with examples provides an overview!

What is the syntax of SQL SELECT?

The basic syntax of SQL SELECT looks as follows:

SELECT  *
FROM  Table
sql

It uses the following parameters:

  • SELECT: Selects the records and columns that are relevant for your query or action. You can name specific columns using primary or foreign keys or use an asterisk * to copy all the data in the source table.
  • FROM: Specifies the table that the records and columns are located in.

Additional optional elements include:

  • WHERE: An optional SQL WHERE clause can be used to set criteria that the data from the source table should fulfill.
  • GROUP BY: Groups target data in groups or categories.
  • ORDER BY: Sorts the data that you retrieve using SELECT in an order of your choosing. Can be further specified with ASC for ascending order or DESC for descending.
  • SELECT TOP: Limits the number of results that are displayed.
  • SELECT DISTINCT: Removes duplicates from the records in the result table.

What is SQL SELECT used for?

SQL SELECT forms the foundation of most queries, making it indispensable for database management systems. It’s used across industries in fields like marketing and sales, human resources, finance, logistics and production.

Here are some practical use cases from different industries:

  • Limiting data analyses of tables with customer data to specific columns like ‘ID’, ‘Address’ or ‘Name’
  • Selecting products or services based on geographic or demographic factors
  • Measuring the success of marketing campaigns using keywords like traffic, interactions and conversions
  • Individualising email campaigns, generating leads or creating offers
  • Analysing suspicious transactions using selected records related to average values or threshold values
  • Managing employee data or application data
  • Monitoring inventory or quality control
Tip

You’re looking for a flexible, scalable, individualised server and hosting solution? Then SQL Server Hosting from IONOS might be right for you – with fast access times, high performance and fail safe security.

VPS Hosting
Fully virtualised servers with root access
  • Unlimited traffic and up to 1 Gbit/s bandwidth
  • Fast SSD NVMe storage
  • Free Plesk Web Host Edition

Examples of SQL SELECT in use

We’ll now take a closer look at how SQL SELECT works, using 2 examples.

Retrieving customer information

In this example you want to retrieve information from the ‘Name’, ‘Address’ and ‘CustomerID’ columns in a table called ‘Customers’:

SELECT  Name, Address, CustomerID
FROM  Customers
sql

Retrieving and sorting orders from a certain product category

In this next example, you want to retrieve all the orders for electronics products, in the ‘Product_category’ column in a table called ‘Orders’ and sort them in descending order based on price.

SELECT  Products, Product_category, Price
FROM  Orders
WHERE  Product_category =  'Electronics'
ORDER BY  Price  DESC
sql

Are there alternatives to SQL SELECT?

SQL SELECT is a central element in SQL queries and database management. For this reason, there is no alternative function for retrieving information from databases.

Was this article helpful?
Page top