SQL SELECT

SQL SELECT Statement

The SELECT statement retrieves data from a database.

The data is returned in a table-like structure called a result-set.

SELECT is the most commonly used operation in a database.

Example

#

Problem: List all suppliers in Italy.

SELECT *
  FROM Supplier
 WHERE Country = 'Italy'

Syntax

SELECT syntax.

SELECT column-names
  FROM table-name

To include all columns use *

SELECT *
  FROM table-name

More Examples

SQL SELECT Wildcard

CUSTOMER
Id
FirstName
LastName
City
Country
Phone
Problem: List all customers.
SELECT * 
  FROM Customer
Result:  91 records
Id FirstName LastName City Country Phone
1 Maria Anders Berlin Germany 030-0074321
2 Ana Trujillo México D.F. Mexico (5) 555-4729
3 Antonio Moreno México D.F. Mexico (5) 555-3932
4 Thomas Hardy London UK (171) 555-7788
5 Christina Berglund Luleå Sweden 0921-12 34 65

SQL SELECT Columns

CUSTOMER
Id
FirstName
LastName
City
Country
Phone
Problem: List the first name, last name, and city of all customers.
SELECT FirstName, LastName, City 
  FROM Customer
Result:  91 records
FirstName LastName City
Maria Anders Berlin
Ana Trujillo México D.F.
Antonio Moreno México D.F.
Thomas Hardy London
Christina Berglund Luleå

You may also like



Guides