Entering content frame

This graphic is explained in the accompanying text Selecting, Arranging, and Renaming Columns Locate the document in the library structure

You can select specific columns in the query and arrange and rename these columns in the results table.

Prerequisites

You require the demo data for the SQL Tutorial.

Start the query tool SQL Studio as database administrator MONA with password RED and log on to the demo database instance DEMODB.

Selecting Specific Columns

To select columns from a table, specify the desired column name after the keyword SELECT. Use commas to separate the column names in this list. Blank characters are optional.

 

SELECT firstname, name
  FROM hotel.customer

Displaying the first and last names of all customers

Result

FIRSTNAME

NAME

Jenny

Porter

Peter

Brown

?

Datasoft

Rose

Brian

Mary

Griffith

Martin

Randolph

Sally

Smith

Mike

Jackson

Rita

Doe

George

Howe

Frank

Miller

Susan

Baker

Joseph

Peters

?

TOOLware

Antony

Jankins

Selecting All Columns

Instead of the list of column names, you can also enter *.

 

SELECT *
  FROM hotel.customer

The system displays the contents of the entire customer table. The columns are displayed in the order you defined when you created the table.

Arranging Columns

You can arrange the columns to be displayed in any order you desire. To do so, enter the column names in the desired order after the keyword SELECT.

 

SELECT name, firstname
  FROM hotel.customer

Displaying the last and first names of all customers

Result

NAME

FIRSTNAME

Porter

Jenny

Brown

Peter

Datasoft

?

Brian

Rose

Griffith

Mary

Randolph

Martin

Smith

Sally

Jackson

Mike

Doe

Rita

Howe

George

Miller

Frank

Baker

Susan

Peters

Joseph

TOOLware

?

Jankins

Antony

 

Renaming Columns

You can rename the columns to be displayed.

 

SELECT zip, name city_name
  FROM hotel.city
    WHERE state = 'NY'

Displaying the zip code and city/place name of all cities/places in the state of NY

Result

ZIP

CITY_NAME

10019

New York

10580

New York

11788

Long Island

12203

Albany

 

See also:

SQL  Reference Manual, Structure linkQUERY Expression (query_expression), Structure linkSelected Column (select_column), Structure linkTable Expression (table_expression)

More examples for Data Query

 

Leaving content frame