Simple Queries
The most basic of queries is to retrieve all of the rows and columns of a table. The easiest way to do this is to use the following statement:
select_stmt: SELECT * FROM table_name
The "*" indicates that all of the columns declared in table_name are to be returned. Thus, you can enter the following statement to see all of the account managers in the acctmgr
table in the bookshop database.
select * from acctmgr; MGRID NAME HIRE_DATE COMMISSION ALFRED Kralik, Alfred 1997-07-02 0.025 AMY Zonn, Amy 1994-07-06 0.025 BARNEY Noble, Barney 1972-05-08 0.035 FRANK Doel, Frank 1987-02-13 0.030 JOE Fox, Joe 1998-12-18 0.025 KATE Kelly, Kathleen 1998-12-18 0.025 KLARA Novac, Klara 1990-01-02 0.025
Of course, if you only need to see some but not all of the columns in a table, those columns can be individually listed as indicated in the following syntax.
select_stmt: SELECT column_name[, column_name]… FROM table_name
Each specified column_name must identify a column that is declared in table_name. The next example retrieves the name, city, and email address of each bookshop patron.
select name, city, email from patron; NAME CITY EMAIL Carlos Slim Helu Acapulco richest@nomail.com William Gates, III Redmond bill.gates@microsoft.com Warren Buffett Omaha berkshire@berkshirehathaway.com Mukesh Ambani Mumbai muki@nomail.com Bernard Arnult Cannes barnult@eposte.co.fr Stephen Jobs Cupertino founder@apple.com Scrooge McDuck Anaheim scrooge@disneycorp.com Richie Rich San Diego richierich@apecomics.com Jed Clampett Beverly Hills richhillbilly@cbs.com Bruce Wayne Gotham City bruce@brucewayne.com Thurston Howell III Newport lovey@gilligan.com Artimis Fowel II Dublin artimis@fowlmanor.com Charles Montgomery Burns Springfield monty@springfieldpower.com Jay Gatsby West Egg jimmy@bootleg.com Lucille Bluth Newport Beach lucille@bluthco.com Chatsworth Osborne Jr. Haddonfield mummsiesboy@blueblood.com Jean Luc Picard San Francisco jlpicard@enterpise.ufp.gov Jeffrey Bezos Seattle bezos@amazoncorp.com Giorgio Armani Piacenza gio@armani.com