LIKE, IN and BETWEEN · LIKE, IN ו-BETWEEN
Matching text patterns with LIKE
= only matches text exactly. To match a pattern, use LIKE with two wildcards:
%stands for any run of characters (including none)_stands for exactly one character
'S%' means "starts with S". '%a%' means "contains an a". '_o%' means "an o as the second letter".
התאמת דפוסי טקסט עם LIKE
= מתייחס רק לטקסט בדיוק. כדי להתאים דפוס, השתמש ב-LIKE עם שני מקרי ג'oker:
%מייצג כל רצף של תווים (כולל רצף ריק)_מייצג בדיוק תווה אחד
SELECT name FROM student WHERE name LIKE 'S%';
'S%' פירושו "מתחיל ב-S". '%a%' פירושו "מכיל an a". '_o%' פירושו "an o כאות השנייה".
Lists and ranges: IN and BETWEEN
Two more handy tests:
IN (…)matches any value in a list:WHERE form IN ('11A', '11C')BETWEEN low AND highmatches a range, including both ends:
Both are shorter than writing several ORs.
רשימות וטווחים: IN ו-BETWEEN
שני מבחנים נוספים שימושיים:
IN (…)מתאים לכל ערך ברשימה:WHERE form IN ('11A', '11C')BETWEEN low AND highתואם טווח, כולל את שתי הקצוות:
SELECT name, score FROM student WHERE score BETWEEN 70 AND 90;
שניהם קצרים מכתיבת מספר ORs.
Common mistakes
- In
LIKE,%matches any text:'A%'means "starts with A". BETWEEN a AND bincludes both ends.
טעויות נפוצות
- ב-
LIKE,%תואם כל טקסט:'A%'פירושו "מתחיל ב-A". BETWEEN a AND bכולל את שתי הקצוות.
Pattern & range filters · מסנני דפוס וטווח
LIKE / IN / BETWEEN are all WHERE — they keep matching rows. · LIKE / IN / BETWEEN הם כולם WHERE — הם משאירים את שורות ההתאמה.
Show the name of every student whose name contains the letter a. Use LIKE with %. · הצג את הname של כל תלמיד ששמו מכיל את האות a. השתמש בLIKE עם %.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.
Show the name and score of students whose score is between 70 and 90 (inclusive). Use BETWEEN. · הצג את הname והscore של תלמידים whose score is בין 70 ל-90 (כולל). השתמש בBETWEEN.
Click Run to see the output here. · לחץ על הרץ כדי לראות את התוצא כאן.