SQL SQL MOC


The SELECT command retrieves data from one or more tables in a database and the FROM identifies the table to retrieve data from.

SELECT comma, separated, fields
FROM tablename;

Wildcard

To extract all data from the table, the wildcard operator, *, can represent all columns.

SELECT * FROM customers;

Example

customers table:

customerIdfirstNamelastNameaddresscitycountry
1UrsaVasquezP.O. Box 878, 8416 Nullam St.WorcesterUnited States
2QuynMeyerP.O. Box 670, 7155 Tincidunt St.PriceCanada
3OrliKlein4981 Gravida St.Barrow-in-FurnessUnited Kingdom
4TallulahHines6279 Pellentesque StreetOmahaUnited States
5JoelRossP.O. Box 842, 4634 Egestas AvenueClovenfordsUnited Kingdom
6CharlotteRamos794-1654 A Rd.AkronUnited States
7DennisAveryP.O. Box 506, 4804 Molestie AvenueMatlockUnited Kingdom
8IgorMalone6627 Porttitor Rd.IrvineUnited Kingdom
9ConnorWitt5979 Vel St.TainUnited Kingdom
10KarenMarquezAp 524-1173 Metus. RoadAnnapolis RoyalCanada

To get the firstName and lastName of every customer in the table:

SELECT firstName, lastName FROM customers;