Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Logical operators.

Slides:



Advertisements
Similar presentations
Using the Set Operators
Advertisements

Database Fundamentals
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Physical.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Self-joins,
Microsoft Enterprise Consortium Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Database Fundamentals Defining.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Create Student-Team.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Aggregate.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals The Data.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Data.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Evaluating.
Writing Basic SQL SELECT Statements. Capabilities of SQL SELECT Statements A SELECT statement retrieves information from the database. Using a SELECT.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Greenhouse Database.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Type II (Correlated)
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
SOUL INSTALLATION Step-1 For this Please Install the Version 7.0 or SQL Server 2000 or onwards.
WRITING BASIC SQL SELECT STATEMENTS Lecture 7 1. Outlines  SQL SELECT statement  Capabilities of SELECT statements  Basic SELECT statement  Selecting.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Introduction.
Computer Science 101 Web Access to Databases SQL – Extended Form.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Using two.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SQL Server.
Enhancements to the GROUP BY Clause Fresher Learning Program January, 2012.
DAY 14: ACCESS CHAPTER 1 Tazin Afrin October 03,
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Test.
® Microsoft Office 2010 Access Tutorial 3 Maintaining and Querying a Database.
DAY 12: DATABASE CONCEPT Tazin Afrin September 26,
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SELECT … FROM.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Nested aggregate.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Aggregating.
Views Lesson 7.
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making Chapter.
SQL for Data Retrieval. Running Example IST2102 Data Preparation Login to SQL server using your account Select your database – Your database name is.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals SELECT … FROM.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Physical.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Sorting output.
Unit 5 Microsoft SQL Server and MySQL. Key Concepts DBMS variations SQL Server features SQL Server Management Studio MySQL features Scripts Queries Database.
Microsoft Office 2003: Advanced 1 ADVANCED MICROSOFT ACCESS Lesson 10 – Analyzing Data.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL In-Line Subquery.
In this session, you will learn to: Use functions to customize the result set Summarize and group data Objectives.
SQL for Data Retrieval. Save your SQL Scripts When working with SQL Management Studio, you should keep saving your scripts as a.sql file to somewhere.
MS ACCESS – FORMS AND REPORTS Naman Kohli October 31,
15 Copyright © Oracle Corporation, All rights reserved. Using SET Operators.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL Equi-Join One-sided.
Copyright © 2004, Oracle. All rights reserved. Using the Set Operators.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Set Operators:
+ Complex SQL Week 9. + Today’s Objectives TOP GROUP BY JOIN Inner vs. Outer Right vs. Left.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals WHERE clause.
Lab 1 Writing Interactive Queries CISB514 Advanced Database Systems.
1 Connecting to a Database Server. 2 We all have accounts, with a single database each, on a Microsoft SQL Server on the USF network: allman.forest.usf.edu.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Advanced SQL The relational.
SQL Server 2012 Session: 1 Session: 4 SQL Azure Data Management Using Microsoft SQL Server.
5 Copyright © 2008, Oracle. All rights reserved. Testing and Validating a Repository.
Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Database Fundamentals Data.
Create Views Using a Graphical Designer Database Administration Fundamentals LESSON 2.3b.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Create Views Using T-SQL Database Administration Fundamentals LESSON 2.3a.
Microsoft Office Access 2010 Lab 3
Exploring Excel Chapter 5 List and Data Management: Converting Data to
Group Functions Lab 6.
Using the Set Operators
20761A 11: Using Set Operators Module 11   Using Set Operators.
Using Subqueries to Solve Queries
Using the Set Operators
Microsoft Enterprise Consortium Type I Subquery
Database Fundamentals
Logic You will learn three common logical operations that will be applied in much of the course (spreadsheets, databases, web searches and both programming.
Using Subqueries to Solve Queries
Using CASE Value expression
Using Subqueries to Solve Queries
Using Subqueries to Solve Queries
Using the Set Operators
Presentation transcript:

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium SQL Fundamentals Logical operators in the WHERE clause 1 Microsoft Enterprise Consortium Microsoft Enterprise Consortium: Microsoft Faculty Connection/Faculty Resource Center

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium What you need … Log in to MEC for this lesson and into MSSMS (Microsoft SQL Server Management Studio). ◦Be sure to select your account ID under Database in the Object Explorer pane, similar to the example shown here. You need to be familiar with some of the concepts presented in earlier lessons in this SQL Fundamentals series. 2

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Logical Operators: AND The WHERE clause in the SELECT statement allows you to filter output based on a single criterion or several criteria. To use more than one criterion in the WHERE clause you need to learn about logical operators. AND ◦The AND operator specifies that two conditions be met. ◦For example: List employees in marketing who were hired before  Department = ‘marketing’  AND Hire date < 01/01/2005 3

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Logical Operators: OR OR ◦The OR operator specifies that at least one condition be met, though both may be. ◦For example: List employees who work in the Southwest or Northwest regional office.  Office location = Southwest  OR office location = Northwest 4

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Logical Operators: Output for AND 5 Condition 1 ANDCondition 2Display Data? NO Don’t display. YESNODon’t display. NOYESDon’t display. YES Display. Assume you have a SELECT statement with the AND operator in the WHERE clause. When is data displayed? The table below shows the possible combinations when evaluating two conditions using the AND operator. YES means the condition is met.

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Logical Operators: Output for OR 6 Condition 1 ORCondition 2Display Data? NO Don’t display. YESNODisplay. NOYESDisplay. YES Display. Assume you have a SELECT statement with the OR operator in the WHERE clause. When is data displayed? The table below shows the possible combinations when evaluating two conditions using the OR operator. YES means the condition is met.

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Query S-T database using AND operator Show students in the ITPROS team with an ISYS major. /* Show students in the ITPROS team AND with an ISYS major. */ select std_teamID, stdmajor, stdfname, stdlname from students where std_teamID = 'ITPROS' AND stdmajor = 'ISYS'; 7

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Query S-T database using OR operator Show students majoring in computer science or accounting. /* Show students who are majoring computer science (COMPSC) OR accounting (ACCT). */ select std_teamID, stdmajor, stdfname, stdlname from students where stdmajor = 'COMPSC' OR stdmajor = 'ACCT'; 8

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Using operator OR with AND /* Show students majoring in accounting OR marketing AND that are in the ITPROS team OR the SYSDES team.*/ select std_teamID, stdmajor, stdfname, stdlname from students where stdmajor = 'ACCT' OR stdmajor = 'MKTG' AND std_teamID = 'ITPROS' OR std_teamID = 'SYSDES'; 9 Show students majoring in accounting or marketing that are in team ITPROS or SYSDES. Is there a problem with this output?

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Using operator OR with AND /* Show students majoring in accounting OR marketing AND that are in the ITPROS team OR the SYSDES team.*/ select std_teamID, stdmajor, stdfname, stdlname from students where ( stdmajor = 'ACCT' OR stdmajor = 'MKTG ') AND ( std_teamID = 'ITPROS' OR std_teamID = 'SYSDES' ) ; 10 Show students majoring in accounting or marketing that are in team ITPROS or SYSDES.

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Logical Operators: NOT /* Show students who are NOT in ITPROS and NOT in SYSDES. */ select std_teamID, stdmajor, stdfname, stdlname from students where NOT std_teamID = 'ITPROS' AND NOT std_teamID = 'SYSDES'; 11 Can you think of a way to write the SQL without using NOT? You can use NOT to negate an evaluation. Show students who are NOT in the ITPROS and SYSDES teams.

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium What was covered … Logical operators in the WHERE clause. ◦AND ◦OR  It is best to use parentheses around OR conditions. ◦NOT 12

Prepared by Jennifer Kreie, New Mexico State UniversityHosted by the University of Arkansas Microsoft Enterprise Consortium Resources Microsoft Faculty Connection—Faculty Resource Center Microsoft Transact-SQL Reference AdventureWorks Sample Database 13