Numberedheadings | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||
|
...
pgAdmin includes some standard scripts and functions that are available by right-clicking on table name. These allow you to view all, or a subset of the data in a table, or construct common SQL scripts. |
...
Querying dataA simple query might return a sub-set of the data held within the database. In English there are multiple ways of posing a question, whereas in SQL you need to be specific about the language you use and the precise columns, tables, schemas and databases you are referring to. To generate a list of names of all the Parishes and their areas in hectares within the county of Surrey, the SQL query needed might look like this:
Note keywords or statements like SELECT, FROM and WHERE are not case case sensitive, but by convention we use uppercase for all SQL keywords in order to make queries easier to read. Queries can be composed as a single line, or spread over a number of lines to ease reading. A semicolon ( ; ) is used to signal to PostgreSQL the end of an SQL statement. Single quotes contain string values e.g. name = ‘Epsom’. Only use these with string data types such as text and character varying. String values are case sensitive so Double quotes must enclose database object names that:
SELECT
[select_list] can be a single column or a list of columns, where a comma is used to separate the individual columns. To return all columns of the table, use an asterisk ( * ) in place of [select_list]. The [select_list] may also contain an expressions or literal values. The FROM clause specifies the name of the table from which you want to select data The SELECT statement can extended by including additional clauses:
Retrieve data from a table |
...
SELECT DISTINCTThe DISTINCT clause is used in a SELECT statement to remove duplicate values. It can be applied to one or more columns in a table. Retrieve unique values from a table |
...
Sorting resultsThe ORDER BY clause allows you to sort rows returned by a SELECT clause in ascending or descending order using ASC or DESC options. It is possible to sort based on multiple columns by separating expressions with a comma. Sort data | ||||||||||||||||||||||||||||||||||||
Info | ||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
WHERE
|
...
SQL in QGISQGIS can be used as an alternative interface to pgAdmin for running SQL queries. Display the distribution of data |
Info |
---|
|
...