SELECT (Databases)

Why Trust Techopedia

What Does SELECT (Databases) Mean?

A SELECT is the fundamental statement of structured query language (SQL).

Advertisements

The SELECT statement, which follows a consistent and specific format, begins with the SELECT keyword followed by the columns to be included in the format. If an asterisk (*) is placed after SELECT, this sequence is followed by the FROM clause that begins with the keyword FROM, followed by the data sources containing the columns specified after the SELECT clause. These data sources may be a single table, combination of tables, subquery or view.

Optional clauses may be added but are not mandatory, i.e., the WHERE clause that gives conditions for returning data, or the ORDER BY clause that sorts output with one or more of the specified columns.

Techopedia Explains SELECT (Databases)

One of the first database administration lessons is the SELECT statement, which forms the beginning of any SQL script used to query data. SELECT is the first keyword in the SELECT statement, which, like all SQL statements, is not case-sensitive.

To illustrate the SELECT statement in an example, assume that a bank database contains a CUSTOMER_MASTER table that stores basic customer details and contains several columns named as follows:

  • customer_id
  • social_security_no
  • surname
  • firstname
  • email_address
  • physical_address
  • date_of_birth
  • gender

The following SELECT statement is used to query all table data:

SELECT * FROM customer_master.

The following SELECT statement is used to sort results by customer surnames:

SELECT * FROM customer_master ORDER BY surname

To list customer surnames, first names and dates of birth, the asterisk (*) is replaced with the corresponding column names, as follows:

SELECT surname, firstname, date_of_birth FROM customer_master

To run a query of all female customers sorted by date of birth, the following statement is issued:

SELECT * FROM customer_master WHERE gender=’F’ ORDER BY date_of_birth

Note: The WHERE clause is now used to restrict output.

This explanation is a simple primer that demonstrates the power of the SELECT statement and may be used to build complex and elaborate queries beyond this scope. However, all SELECT statements, regardless of scope, are required to consistently follow the basic rules outlined above.

Advertisements

Related Terms

Margaret Rouse
Editor

Margaret jest nagradzaną technical writerką, nauczycielką i wykładowczynią. Jest znana z tego, że potrafi w prostych słowach pzybliżyć złożone pojęcia techniczne słuchaczom ze świata biznesu. Od dwudziestu lat jej definicje pojęć z dziedziny IT są publikowane przez Que w encyklopedii terminów technologicznych, a także cytowane w artykułach ukazujących się w New York Times, w magazynie Time, USA Today, ZDNet, a także w magazynach PC i Discovery. Margaret dołączyła do zespołu Techopedii w roku 2011. Margaret lubi pomagać znaleźć wspólny język specjalistom ze świata biznesu i IT. W swojej pracy, jak sama mówi, buduje mosty między tymi dwiema domenami, w ten…