The AND keyword
CoddyのSQLジャーニー「基礎」セクションの一部 — レッスン 6/72。
AND キーワードは、両方の条件が真(true)でなければならないことを意味します。どちらか一方でも真でない場合、条件を満たしたことにはなりません。
例えば、以下のような <b>people</b> テーブルがあるとします:
| name | age | gender |
|---|---|---|
| Joas | 13 | male |
| Holwa | 17 | male |
| Nohlas | 24 | female |
| Polar | 23 | male |
| Loopa | 18 | female |
以下のクエリ:
SELECT *
FROM people
WHERE gender = "female" AND age < 20これは、gender が "female" であり、age が 20 未満であるすべてのレコードを検索していることを意味します。
結果は次のようになります:
| name | age | gender |
|---|---|---|
| Loopa | 18 | female |
注: SQLでは、文字列値はダブルクォーテーション "female" またはシングルクォーテーション 'female' のいずれかで記述できます。ほとんどのSQLデータベースで両方が許容されます。
チャレンジ
簡単利用可能なテーブルとカラム:
people:name,age,statusテーブル: people
name age status Charles 28 employed Fatima 38 unemployed Eric 11 unemployed Diya 44 employed Hanna 22 employed Ali 20 unemployed Gabriel 37 employed Beatriz 17 employed Troy 29 unemployed Angelica 32 employed
people テーブルから、age が 20 歳から 28 歳まで(20 歳と 28 歳を含む)のすべての人を取得してください。
自分で試してみよう
SELECT *
FROM people
-- 以下にコードを書いてください
WHEREこのレッスンには短いクイズがあります。レッスンを始めて解答し、進捗を記録しましょう。
基礎のすべてのレッスン
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columns