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 [email protected] William Gates, III Redmond [email protected] Warren Buffett Omaha [email protected] Mukesh Ambani Mumbai [email protected] Bernard Arnult Cannes [email protected] Stephen Jobs Cupertino [email protected] Scrooge McDuck Anaheim [email protected] Richie Rich San Diego [email protected] Jed Clampett Beverly Hills [email protected] Bruce Wayne Gotham City [email protected] Thurston Howell III Newport [email protected] Artimis Fowel II Dublin [email protected] Charles Montgomery Burns Springfield [email protected] Jay Gatsby West Egg [email protected] Lucille Bluth Newport Beach [email protected] Chatsworth Osborne Jr. Haddonfield [email protected] Jean Luc Picard San Francisco [email protected] Jeffrey Bezos Seattle [email protected] Giorgio Armani Piacenza [email protected]