_
matches any single character
% matches 0 or more characters of any value
\
escapes special characters (e.g. \% matches % and \\ matches \ )
all other characters match themselves
As an example of the LIKE operator, it is possible to search for anyone in the finance
department who s last name consists of any letter followed by ughes , such as Hughes. The
query to perform this operation could look like
SELECT first_name, last_name FROM emp_details
G
WHERE dept = finance and last_name like _ughes
The RLIKE operator provides access to the power of the UNIX standard regular
expression syntax. The UNIX regular expression syntax provides far greater
functionality than SQL s LIKE syntax. The UNIX regex syntax does not use the _ or
% characters in the way SQL s regex does (as outlined above). The syntax available in
the RLIKE operator is
.
matches any single character
^ When used as the first charactr in a regex, the caret character forces the match to
start at the first character of the string
$ When used as the last charactr in a regex, the dollar sign forces the match to end at
the last character of the string
[ ] By enclosing a group of single characters withing square brackets, the regex will
match a single character from the group of characters. If the ] character is one of the
characters you wish to match you may specifiy it as the first character in the group
without closing the group (e.g. []abc] would match any single character that was
either ] , a , b , or c ). Ranges of characters can be specified within the group using
the first last syntax (e.g. [a z0 9] would match any lower case letter or a digit). If
the first charactr of the group is the ^ character the regex will match any single
character that is
not
contained within the group.
* If any regex element is followed by a * it will match
zero or more
instances of the
regular expression.
The power of a relational query language starts to become apparent when you join tables
together during a select operation. Lets say you had two tables defined, one containing staff
details and another listing the projects being worked on by each staff member, and each staff
member has been assigned an employee number that is unique to that person. You could
generate a sorted list of who was working on what project with a query like:
SELECT emp_details.first_name, emp_details.last_name, project_details.project
G
FROM emp_details, project_details
WHERE emp_details.emp_id = project_details.emp_id
ORDER BY emp_details.last_name, emp_details.first_name
mSQL places no restriction on the number of tables "joined" during a query so if there
were 15 tables all containing information related to an employee ID in some manner,
data from each of those tables could be extracted, by a single query. One key point to
note regarding joins is that you must qualify all column names with a table name.
mSQL does not support the concept of uniquely named columns spanning multiple
tables so you are forced to qualify every column name as soon as you access more than
one table in a single select.
<
New Page 1
Godaddy Web Hosting