• Embed Doc
  • Readcast
  • Collections
  • CommentGo Back
Download
 
Page 1 of 9
http://ThrivingAndLiving.blogspot.com 
Laboratory Activity 3
Comparison Operators in MySQL
Objectives
At the end of the activity, student is expected to perform/identify the following:
 
Identify the different relational/comparison operators;
 
Use GROUP BY clause;
 
Combine Aggregate functions such as COUNT();
 
Impose selection criteria using HAVING clause.This is a continuation of Laboratory Activity 2. In order to gain full understandingin-depth, we suggest that you do the said lab activity first before proceeding on this activity.You may visit it athttp://thrivingandliving.blogspot.com/2009/12/mysql-query-browser-tutorial.html.
Relational/Comparison Operators
WHERE clause can use other operators to limit records. The following are comparisonoperators that support WHERE:
Operator Description
= Equal to<> or != Not equal to< Less than<= Less than or equal to> greater than>= greater than or equal toLIKE Used to compare stringsBETWEENChecks for values betweena rangeIN Checks for values in a listNOT INEnsures the value is not inthe list
Table 3.
Relational / Comparison OperatorsWhen working with strings, % and _ (underscore) can be used as wildcards to retrievekeywords from rows from the search table.
 
Page 2 of 9
http://ThrivingAndLiving.blogspot.com 
Let us use again MySQL Query Browser application. Click Start | Programs | MySQL| MySQL Query Browser.Supply
localhost
 
at server host;
root
at username. We will use the existingdatabase that we did on Activity 2:
my_store
. Enter the password you have designated onyour server. See Figure 31.
Figure 31
. Connecting to serverWe will now list all rows of customers who have address in the state of NewYork. Figure 32 has the following output:SELECT name, addressFROM customersWHERE address LIKE '%ny%';
Figure 32
. Using % as wild card
 
Page 3 of 9
http://ThrivingAndLiving.blogspot.com 
The statement below retrieves all rows that begins with p with six charactersfollowing it (six underscores were used). Figure 33 has the output.SELECT description, unitFROM productsWHERE description LIKE '%P______';
Figure 33
. Using _ as wildcardAND and OR can be combined to qualify search criteria. The following statementsproduce Figure 34 and Figure 35.SELECT description, unitFROM productsWHERE unit='ea' OR unit='pc';
Figure 34
. Using OR on selection criteria
of 00

Leave a Comment

You must be to leave a comment.
Submit
Characters: ...
You must be to leave a comment.
Submit
Characters: ...