Comp12 cont…. Using Quotes Note that we have used single quotes around the conditional values in the examples. SQL uses single quotes around text values.

Slides:



Advertisements
Similar presentations
Aggregate Functions Presenter: Sushma Bandekar CS 157(A) – Fall 2006.
Advertisements

Exploring Microsoft Access
COMP 3715 Spring 05. Working with data in a DBMS Any database system must allow user to  Define data Relations Attributes Constraints  Manipulate data.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
Session 4 SQL Structured Query Language. SQL Modes of use –Interactive –Embedded Purpose –Create database –Create, Read, Update, Delete.
© 2002 by Prentice Hall 1 David M. Kroenke Database Processing Eighth Edition Chapter 9 Structured Query Language.
Introduction to Oracle9i: SQL1 SQL Group Functions.
Structured Query Language Part I Chapter Three CIS 218.
Mary K. Olson PS Reporting Instance – Query Tool 101.
Concepts of Database Management Sixth Edition
Microsoft Access 2010 Chapter 7 Using SQL.
Computer Science 101 Web Access to Databases SQL – Extended Form.
SQL Operations Aggregate Functions Having Clause Database Access Layer A2 Teacher Up skilling LECTURE 5.
DATABASES AND SQL. Introduction Relation: Relation means table(data is arranged in rows and columns) Domain : A domain is a pool of values appearing in.
INFORMATION TECHNOLOGY IN BUSINESS AND SOCIETY SESSION 16 – SQL SEAN J. TAYLOR.
SQL Basics. SQL SQL (Structured Query Language) is a special-purpose programming language designed from managing data in relational database management.
Xin  Syntax ◦ SELECT field1 AS title1, field2 AS title2,... ◦ FROM table1, table2 ◦ WHERE conditions  Make a query that returns all records.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 3: Introduction.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
Chapter 6 Group Functions. Chapter Objectives  Differentiate between single-row and multiple-row functions  Use the SUM and AVG functions for numeric.
Chapter 3 Single-Table Queries
Microsoft Access 2010 Chapter 7 Using SQL. Change the font or font size for SQL queries Create SQL queries Include fields in SQL queries Include simple.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
CS&E 1111 AcQueries Querying in Access Sorting data Aggregating Data Performing Calculations Objectives: Learn how to use the Access Query Design Tool.
Database A collection of related data. Database Applications Banking: all transactions Airlines: reservations, schedules Universities: registration, grades.
SQL Review Tonga Institute of Higher Education. SQL Introduction SQL (Structured Query Language) a language that allows a developer to work with data.
Database Queries. Queries Queries are questions used to retrieve information from a database. Contain criteria to specify the records and fields to be.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Structured Query Language ( 結構化查詢語言 ) Database Programming CREATE TABLE … ALTER TABLE… ADD/DROP/MODIFY (…) DESC … DROP TABLE … RENAME … TO … INSERT INTO.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) Structured Query Language Introduction to SQL Structured Query Language.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
Using Special Operators (LIKE and IN)
Concepts of Database Management Seventh Edition
Lecture7:Data Manipulation in SQL Advanced Queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture7 1.
Querying a Database - A question or an inquiry (dictionary.com) - WHAT ARE WE ASKING QUESTIONS ABOUT? THE DATA - BY ASKING QUESTIONS OF THE DATA WE OBTAIN?
Nitin Singh/AAO RTI ALLAHABAD 1 SQL Nitin Singh/AAO RTI ALLAHABAD 2 OBJECTIVES §What is SQL? §Types of SQL commands and their function §Query §Index.
Topic 1: Introduction to SQL. SQL stands for Structured Query Language. SQL is a standard computer language for accessing and manipulating databases SQL.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
Concepts of Database Management Eighth Edition Chapter 3 The Relational Model 2: SQL.
Database Applications – Microsoft Access Lesson 4 Working with Queries 36 Slides in Presentation.
STRUCTURED QUERY LANGUAGE SQL-II IST 210 Organization of Data IST210 1.
Advanced SELECT Queries CS 146. Review: Retrieving Data From a Single Table Syntax: Limitation: Retrieves "raw" data Note the default formats… SELECT.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Course title: Database-ii Chap No: 03 “Advanced SQL” Course instructor: ILTAF MEHDI.
© 2002 by Prentice Hall 1 Structured Query Language David M. Kroenke Database Concepts 1e Chapter 3 3.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Oracle & SQL. Oracle Data Types Character Data Types: Char(2) Varchar (20) Clob: large character string as long as 4GB Bolb and bfile: large amount of.
1 Chapter 3 Single Table Queries. 2 Simple Queries Query - a question represented in a way that the DBMS can understand Basic format SELECT-FROM Optional.
Access Query Design. IT Fundamentals2 Access Query Design The Query design screen provides a mechanism for selecting specific data from datafile(s) by:
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
SQL: Structured Query Language It enables to create and operate on relational databases, which are sets of related information stored in tables. It is.
Structured Query Language SQL-II IST 210 Organization of Data IST2101.
Database Design lecture 3_2 Slide 1 Database Design Lecture 3_2 Data Manipulation in SQL Simple SQL queries References: Text Chapter 8 Oracle SQL Manual.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
MySQL DML Commands By Prof. B.A.Khivsara
SQL AGGREGATE FUNCTIONS
Chapter 3 Introduction to SQL(3)
SQL Tutorial.
SQL – Entire Select.
Access: SQL Participation Project
Structured Query Language
Query Functions.
Aggregate Functions.
Shelly Cashman: Microsoft Access 2016
Chapter Name SQL: Data Manipulation
Group Operations Part IV.
Presentation transcript:

Comp12 cont…

Using Quotes Note that we have used single quotes around the conditional values in the examples. SQL uses single quotes around text values (most database systems will also accept double quotes). Numeric values should not be enclosed in quotes.

For text values: This is correct: SELECT * FROM Persons WHERE FirstName = 'Tove' This is wrong: SELECT * FROM Persons WHERE FirstName = Tove

For numeric values: This is correct: SELECT * FROM Persons WHERE Year > 1965 This is wrong: SELECT * FROM Persons WHERE Year > '1965'

IN operator: IN operator in the where clause can be used to check for discrete values.

Example 1: Write a query to get those names of all students whose marks are 90 or 92. Ans: SELECT name FROM student WHERE marks IN (90, 92);

Example 2: Write a query to get details of all students whose belong to class C12 or E12. Ans: SELECT * FROM student WHERE class IN (‘C12’, ‘E12’);

BETWEEN-AND Operator: This operator is used to define a range of values. The lower and higher value is also included in the range of values.

Example: Write a query to display the roll & name of all students whose marks is between 90 & 95. Ans: SELECT roll, name FROM student WHERE marks BETWEEN 90 AND 95;

LIKE operator: This operator is used to check character type fields. It is used to check substrings. There are two types of wild cards used with LIKE operator. Underscore (_): It stands for a single character. e.g.: h_t can stand for hat, hit, hot etc. Percentage (%): It stands for occurrence of 0 or more characters.

Example 1: Select name, roll from student where name like ‘Sh%’;

Example 2: Write a query to display the details of all students whose names start with ‘R’; Ans: SELECT * FROM student WHERE name LIKE ‘R%’;

LOGICAL or BOOLEAN operators: The logical operators AND, OR, NOT are used to have two or more criteria in a single command.

Example 1: Write a query to display the name and roll of all students who are in class C12 and their age is 15. Ans: SELECT name, roll FROM student WHERE class = ’C12’ AND age = 5;

Example 2: Write a query to display the details of all students who are in class E12 or whose age is above 13. Ans: SELECT * FROM student WHERE class = ‘E12’ OR age >13;

Aggregation function: AVG - Get the average of a specified column. COUNT - Get the quantity of values in the column. MAX - Return the maximum value in a specified column. MIN - Return the minimum value in a specified column. SUM - Return the sum of all numeric values in the specified column.

Example: SELECT MAX(population)FROM citylist;WHERE state = 'Indiana';

1. Write the correct SQL commands for the following on the basis of table Supplier.

No.NamePriceSupplierStock 1Motherboard7000Intel20 2Keyboard1000TVSE70 3Mouse500Logitech60 4Soundcard600Samsung50 5Speaker600Samsung25 6Monitor3000Philips22 7CD-ROM2800Creative32 8Printer7900HP10

1.List all Name and Price with price between 3000 and To set the price to 1200 for ‘Keyboard’. 3.To delete rows with stock between 20 and To display Name, Price, stock of all suppliers whose name starts with 'S'. 5.To display supplier without duplication. 6.To insert a row with appropriate values. 7.To increase the stock of all Samsung suppliers. 8.To display all supplier details whose supplier is Philips and stock is above To display name, supplier, stock for name as keyboard or mouse.

1.SELECT Name, Price FROM Supplier WHERE Price BETWEEN 3000 AND 7000; 2.UPDATE Supplier SET Price=Price WHERE Name = ‘Keyboard’; 3.DELETE FROM Supplier WHERE Stock BETWEEN 20 AND 40; 4.SELECT Name, Price, Stock FROM Supplier WHERE Supplier LIKE ‘S%’; 5.SELECT DISTINT Supplier FROM Supplier; 6.INSERT INTO Supplier VALUES(9,’Headphone’, 50, ‘Logitech’, 10); 7.UPDATE Supplier SET Stock=Stock + 10; 8.SELECT * FROM Supplier WHERE Supplier=’Philips’ AND Stock > 40; 9.SELECT Name, Supplier, Stock FROM Supplier WHERE IN(‘Keyboard’,’Mouse’);