データの問合せ


SELECT文は、データテーブルから情報を取得するために使用されます.文の一般的な形式は次のとおりです.

SELECT what_to_select
FROM which_table
WHERE conditions_to_satisfy;

1.すべてのデータを問い合わせる
 
select * from pet;

2.特殊行の問合せ
 
SELECT * FROM pet WHERE name = 'Bowser';
SELECT * FROM pet WHERE birth > '1998-1-1';
SELECT * FROM pet WHERE species = 'dog' AND sex = 'f';
SELECT * FROM pet WHERE species = 'snake' OR species = 'bird';  
AND OR    , AND OR        。          ,                
SELECT * FROM pet WHERE (species = 'cat' AND sex = 'm') OR (species = 'dog' AND sex = 'f');
  

3.クエリ一意レコード使用キーワードDISTINCT
 
SELECT DISTINCT owner FROM pet;

4.並べ替え
 
  :SELECT name, birth FROM pet ORDER BY birth;
  :SELECT name, birth FROM pet ORDER BY birth desc;