Beginning SQL

Beginning SQL Beginning SQL

marjan.fesb.hr
from marjan.fesb.hr More from this publisher
20.07.2013 Views

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

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

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!