Beginning SQL
Beginning SQL Beginning SQL
Chapter 3 When you execute the query, you get the following results: FilmName Sense and Insensitivity Raging Bullocks Continuing the look at logical operators, the next section takes you through the LIKE operator. LIKE Operator 70 The LIKE operator allows you to use wildcard characters when searching a character field. A wildcard character is one that doesn’t match a specific character but instead matches any one character or any of one or more characters. One example of its use would be finding out details of all members in the film club whose surname begins with J. The following table details the two available wildcard characters. Wildcard Description % Matches one or more characters. Note that MS Access uses the asterisk (*) wildcard character instead of the percent sign (%) wildcard character. _ Matches one character. Note that MS Access uses a question mark (?) instead of the underscore (_) to match any one character. The SQL to match all names beginning with a J is as follows: SELECT LastName FROM MemberDetails WHERE LastName LIKE ‘J%’; Remember, if you’re using MS Access you need to change the percent sign (%) to an asterisk (*): SELECT LastName FROM MemberDetails WHERE LastName LIKE ‘J*’; The preceding code fragment produces these results: LastName Jackson Jones Jones Johnson
- Page 130: Inserting Data into the Case Study
- Page 134: The WHERE Clause So far you’ve se
- Page 138: Try It Out Using Logical Operators
- Page 142: Exercises 1. Three new members have
- Page 148: Chapter 3 54 MemberId FirstName 1 K
- Page 152: Chapter 3 The results are as follow
- Page 156: Chapter 3 The results to this query
- Page 160: Chapter 3 FavCategory (CategoryId,
- Page 164: Chapter 3 Logical Operators and Ope
- Page 168: Chapter 3 The statement returns the
- Page 172: Chapter 3 NOT Operator Examples thu
- Page 176: Chapter 3 2. Using the following SQ
- Page 182: In some database systems, the LIKE
- Page 186: The second query is a negative, in
- Page 190: Because both conditions (YearReleas
- Page 194: YearReleased 1984 1980 1977 1975 19
- Page 198: First, the database system orders t
- Page 202: LastName FirstName DateOfBirth Nigh
- Page 206: The preceding SQL returns the follo
- Page 210: If you put square brackets around i
- Page 214: Finally, if you want to use an alia
- Page 218: Member Name The member is called Ka
- Page 222: FilmName YearReleased Rating Sense
- Page 226: Figure 3-1 The first task when tack
Chapter 3<br />
When you execute the query, you get the following results:<br />
FilmName<br />
Sense and Insensitivity<br />
Raging Bullocks<br />
Continuing the look at logical operators, the next section takes you through the LIKE operator.<br />
LIKE Operator<br />
70<br />
The LIKE operator allows you to use wildcard characters when searching a character field. A wildcard<br />
character is one that doesn’t match a specific character but instead matches any one character or any of<br />
one or more characters. One example of its use would be finding out details of all members in the film<br />
club whose surname begins with J.<br />
The following table details the two available wildcard characters.<br />
Wildcard Description<br />
% Matches one or more characters. Note that MS Access uses the asterisk (*)<br />
wildcard character instead of the percent sign (%) wildcard character.<br />
_ Matches one character. Note that MS Access uses a question mark (?)<br />
instead of the underscore (_) to match any one character.<br />
The <strong>SQL</strong> to match all names beginning with a J is as follows:<br />
SELECT LastName FROM MemberDetails<br />
WHERE LastName LIKE ‘J%’;<br />
Remember, if you’re using MS Access you need to change the percent sign (%) to an asterisk (*):<br />
SELECT LastName FROM MemberDetails<br />
WHERE LastName LIKE ‘J*’;<br />
The preceding code fragment produces these results:<br />
LastName<br />
Jackson<br />
Jones<br />
Jones<br />
Johnson