テーブルから情報を取り出すにはSELECT文を使います(参考:PostgreSQL 9.5.4文書 - 7.1. 概要)。
- 出力対象となる項目名(列名、カラム名)はコンマで区切って複数指定できます。
- すべての項目名を出力対象とする場合、項目名にアスタリスク(*)を指定します。
- 条件をつけて返される結果を限定するにはWHERE節を併用してください。
- 返される結果数を限定するにはLIMIT節を併用してください。
- 同一の値を重複して出力しないようにするにはSELECTの代わりにSELECT DISTINCTを使ってください。
書式
SELECT カラム名 FROM テーブル名
例
| Order | Family | Genus | Species | Species_ja |
|---|---|---|---|---|
| Primate | Hominidae | Home | sapiens | ヒト |
| Primate | Cercopithecidae | Macaca | fuscata | ニホンザル |
| Primate | Hominidae | Gorilla | gorilla | ニシゴリラ |
| Cetartiodactyla | Bovidae | Bos | taurus | ウシ |
| Cetartiodactyla | Suidae | Sus | scrofa | イノシシ |
| Cetartiodactyla | Physeteridae | Physeter | macrocephalus | マッコウクジラ |
| Perissodactyla | Equidae | Equus | caballus | ウマ |
| Perissodactyla | Rhinocerotidae | Ceratotherium | simum | シロサイ |
| Rodentia | Muridae | Mus | musculus | ハツカネズミ |
| Rodentia | Muridae | Rattus | norvegicus | ドブネズミ |
SELECT * FROM Mammalia ↓ Order | Family | Genus | Species | Species_ja -------------------------------------------------------------------------------- Primate | Hominidae | Home | sapiens | ヒト Primate | Cercopithecidae | Macaca | fuscata | ニホンザル Primate | Hominidae | Gorilla | gorilla | ニシゴリラ Cetartiodactyla | Bovidae | Bos | taurus | ウシ Cetartiodactyla | Suidae | Sus | scrofa | イノシシ Cetartiodactyla | Physeteridae | Physeter | macrocephalus | マッコウクジラ Perissodactyla | Equidae | Equus | caballus | ウマ Perissodactyla | Rhinocerotidae | Ceratotherium | simum | シロサイ Rodentia | Muridae | Mus | musculus | ハツカネズミ Rodentia | Muridae | Rattus | norvegicus | ドブネズミ SELECT Order,Family FROM Mammalia ↓ Order | Family ---------------------------------- Primate | Hominidae Primate | Cercopithecidae Primate | Hominidae Cetartiodactyla | Bovidae Cetartiodactyla | Suidae Cetartiodactyla | Physeteridae Perissodactyla | Equidae Perissodactyla | Rhinocerotidae Rodentia | Muridae Rodentia | Muridae SELECT DISTINCT Order FROM Mammalia ↓ Order ----------------- Primate Cetartiodactyla Perissodactyla Rodentia






