The Wayback Machine - https://web.archive.org/web/20071011021855/http://sqlcourse2.com:80/boolean.html


Free Newsletters:
DatabaseJournal
DBANews

SQLCourse2
Advanced Online SQL Training
Search Database Journal:
 
HOME News MS SQL Oracle DB2 Access MySQL PHP SQL Etc Scripts Links Forums DBA Talk
internet.com
SQL Courses
1 Start Here - Intro
2 SELECT Statement
3 Aggregate Functions
4 GROUP BY clause
5 HAVING clause
6 ORDER BY clause
7 Combining Conditions & Boolean Operators
8 IN and BETWEEN
9 Mathematical Functions
10 Table Joins, a must
11 SQL Interpreter
12 Advertise on SQLCourse.com
13 Other Tutorial Links
14 Technology Jobs




internet.commerce
Partner With Us
Hurricane Shutters
Managed Hosting
Memory Upgrades
Home Improvement
Corporate Awards
Web Hosting
Plasma Televisions
KVM Switches
Compare Prices
Computer Deals
Holiday Gift Ideas
GPS
Server Racks
Web Hosting Directory

internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers


Analyst Report: Predict 2007--Brace Yourself for the Next Wave of Server Technology. Learn new predictions about server technology including OS virtualization technology.

Combining conditions and Boolean Operators

The AND operator can be used to join two or more conditions in the WHERE clause. Both sides of the AND condition must be true in order for the condition to be met and for those rows to be displayed.


SELECT column1, 
SUM(column2)
FROM "list-of-tables"
WHERE "condition1" AND "condition2";

The OR operator can be used to join two or more conditions in the WHERE clause also. However, either side of the OR operator can be true and the condition will be met - hence, the rows will be displayed. With the OR operator, either side can be true or both sides can be true.

For example:


SELECT employeeid, firstname, lastname, title, salary
FROM employee_info
WHERE salary >= 50000.00 AND title = 'Programmer';

This statement will select the employeeid, firstname, lastname, title, and salary from the employee_info table where the salary is greater than or equal to 50000.00 AND the title is equal to 'Programmer'. Both of these conditions must be true in order for the rows to be returned in the query. If either is false, then it will not be displayed.

Although they are not required, you can use paranthesis around your conditional expressions to make it easier to read:


SELECT employeeid, firstname, lastname, title, salary
FROM employee_info
WHERE (salary >= 50000.00) AND (title = 'Programmer');

Another Example:

SELECT firstname, lastname, title, salary
FROM employee_info
WHERE (title = 'Sales') OR (title = 'Programmer');

This statement will select the firstname, lastname, title, and salary from the employee_info table where the title is either equal to 'Sales' OR the title is equal to 'Programmer'.

Use these tables for the exercises
items_ordered
customers

Review Exercises

  1. Select the customerid, order_date, and item from the items_ordered table for all items unless they are 'Snow Shoes' or if they are 'Ear Muffs'. Display the rows as long as they are not either of these two items.
  2. Select the item and price of all items that start with the letters 'S', 'P', or 'F'.

Click the exercise answers link below if you have any problems.

Answers to these Exercises

Enter SQL Statement here:


SQL Course 2 Curriculum
<<previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14  next>>


Get FREE Symantec Windows Backup and Recovery Resources!
WHITEPAPER:
Comprehensive Online Microsoft. SQL Server Data Protection with Symantec Backup Exec 11d

WHITEPAPER:
Redefining Exchange Server Data Protection with Symantec Backup Exec 11d for Windows Servers

WHITEPAPER:
Disk-Based Data Protection: Achieve Faster Backups and Restores While Reducing Your Backup Windows

FACT SHEET:
11 Reasons to Upgrade to Symantec Backup
Exec 11d

Solutions


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info