Sql Select Where Clause
- We use where clause to specify conditions
- Only if we have conditions we can write where statement
- Where clause can be used with SELECT, UPDATE, and DELETE statements.
- According to the conditions, ‘where statement’ returns true or false value
- If value returns true, that record is listed
In Where Clause we can use operators and statements that specified below
- > bigger
- < small
- >= bigger or equal
- <= small or equal
- = equal
- != not equal
- between x and y
- like
- in
- is null
TO DOWNLOAD THE SAMPLE LİBRARY DATABASE CLICK
Sql Where Clause Examples on Library Database
Sample 1: List the student where student_id equal to 20
1 |
Select * from students where studentId = 20 |
Result Of The Query
1 row listed.
Sample 2: List the books where page count bigger than 200
1 |
Select * from books where pageCount > 200 |
96 rows listed.
Sample 3: List the books where the point value smaller than 120
1 |
Select * from books where point < 120 |
Result Of The Query
168 rows listed.
Sample 4: List the books where pageCount in between 100 and 200
1 |
Select * from books where pageCount between 100 and 200 |
Result Of The Query
61 rows listed.
Sample 5: List the students where student name starts with “a” character
1 |
Select * from students where name like 'a%' |
Result Of The Query
126 rows listed.
Sample 6: List the students who are in 11A class or 11B class
1 |
Select * from students where class = '11A' or class = '11B' |
Result Of The Query
42 rows listed.
Sample 7: List the boys from 11a or 11b
1 |
Select * from students where (class = '11A' or class = '11B') and gender='M' |
Not: Brackets are very important. Detailed information will be written in the subject of operators
Result Of The Query
25 rows listed.
Sample 8:List the students where name contains “b” character and student id in between 100 and 200
1 |
Select * from students where name like '%b%' and studentId between 100 and 200 |
Result Of The Query
17 rows listed.
Sample 9:List the students whose second character of name is a.
1 |
<span class="hljs-keyword">Select</span> * <span class="hljs-keyword">from</span> students <span class="hljs-keyword">where</span> <span class="hljs-keyword">name</span> <span class="hljs-keyword">like</span> <span class="hljs-string">'_a%'</span> |
Result Of The Query
141 rows listed.
Sample 10:List the students whose second character of name from end is “a”.
1 |
<span class="hljs-keyword">Select</span> * <span class="hljs-keyword">from</span> students <span class="hljs-keyword">where</span> <span class="hljs-keyword">name</span> <span class="hljs-keyword">like</span> <span class="hljs-string">'%a_'</span> |
Result Of The Query
29 rows listed.