Book

Table of Contents

Data from Table

To output data from a table, use the FROM keyword, after which the table name is specified.

SELECT cities.name
FROM cities

will output the values of the name field from the cities table.

For a table, a schema can be specified, to which this table belongs:

SELECT cities.name
FROM geo.cities

the cities table, which is located in the geo schema.

You don’t need to specify the table name before the field name if a field with that name exists only in one table used in the query:

SELECT name
FROM cities

Table aliases can also be applied:

SELECT "Cities".name
FROM cities "Cities"

And this is also possible:

SELECT "Cities".name "Name"
FROM cities "Cities"

And like this:

SELECT a.name
FROM cities a

Of course, you can list multiple tables:

SELECT cities.name, countries.name, countries.code
FROM cities, countries

will output city names, country names and codes. You see, the name field exists both in the cities table and in countries. Therefore, we must explicitly specify the table name for these fields. But in this form, I don’t recommend running the query. How to output data from multiple tables will be discussed later.

SELECT cities.*
FROM cities

will output all fields from the cities table

SELECT cities.*, countries.*
FROM cities, countries

will output all fields from the cities and countries tables

SELECT *
FROM cities, countries

will also output all fields of these tables