Select. select Att 1, Att 2, Att 3,…, Att n from Tablename where (condition) Order by att1,att2 |desc; //Order By (Ascending & Descending) Explanation:

Slides:



Advertisements
Similar presentations
WHERE Clause Chapter 2. Objectives Limit rows by using a WHERE clause Use the LIKE operator Effect of NULL values Use compound conditions Use the BETWEEN.
Advertisements

Virtual training week 4 structured query language (SQL)
Database Systems: Design, Implementation, and Management Tenth Edition
1 SQL (Simple Query Language). 2 Query Components A query can contain the following clauses –select –from –where –group by –having –order by Only select.
Introduction to Structured Query Language (SQL)
Kirkwood Center for Continuing Education Introduction to PHP and MySQL By Fred McClurg, Copyright © 2010 All Rights Reserved. 1.
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Nov 24, 2003Murali Mani SQL B term 2004: lecture 12.
Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data
Using Relational Databases and SQL Steven Emory Department of Computer Science California State University, Los Angeles Lecture 2: Single-Table Selections.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
A Guide to SQL, Seventh Edition. Objectives Retrieve data from a database using SQL commands Use compound conditions Use computed columns Use the SQL.
Lecture 6 29/1/15. Number functions Number functions take numbers as input, change them, and output the results as numbers. 2.
1 Copyright © Oracle Corporation, All rights reserved. Writing Basic SQL SELECT Statements.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Using SQL Queries to Insert, Update, Delete, and View Data Date Retrieval from a single table & Calculations © Abdou Illia MIS Spring 2015.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
Chapter 3 Single-Table Queries
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Restricting and Sorting Data. ◦ Limiting rows with:  The WHERE clause  The comparison conditions using =,
2 Copyright © Oracle Corporation, All rights reserved. Restricting and Sorting Data.
2 Copyright © 2004, Oracle. All rights reserved. Restricting and Sorting Data.
4 Copyright © 2006, Oracle. All rights reserved. Restricting and Sorting Data.
Oracle Sequences Sequences are an independent object in the database (not a data type) Sequences have a name and can be used anywhere a value is expected.
Instructor: Jinze Liu Fall Basic Components (2) Relational Database Web-Interface Done before mid-term Must-Have Components (2) Security: access.
BY SATHISH SQL Basic. Introduction The language Structured English Query Language (SEQUEL) was developed by IBM Corporation, Inc., to use Codd's model.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
Database Management COP4540, SCS, FIU Structured Query Language (Chapter 8)
2 第二讲 Restricting and Sorting Data. Objectives After completing this lesson, you should be able to do the following: Limit the rows retrieved by a query.
Copyright © 2004, Oracle. All rights reserved. Retrieving Data Using the SQL SELECT Statement Satrio Agung Wicaksono, S.Kom., M.Kom.
Structured Query Language
1 Querying a Single Table Structured Query Language (SQL) - Part II.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Querying Database ISYS 363.
Structured Query Language SQL Unit 2 An Introduction to Organizing and Retrieving Data with SQL.
CMPT 258 Database Systems The Relationship Model (Chapter 3)
Selecting Data Database Administration Fundamentals LESSON 3.1a.
SQL Miscellaneous Topics. Views A database view is: – a virtual or logical table based on a query. – a stored query. CREATE VIEW viewname AS query; –CREATE.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Jennifer Widom Relational Databases The Relational Model.
IST 220 – Intro to DB Lab 2 Specifying Criteria in SELECT Statements.
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.
7 1 Database Systems: Design, Implementation, & Management, 7 th Edition, Rob & Coronel 7.6 Advanced Select Queries SQL provides useful functions that.
Lecture3b - Chapter 3: Using SQL Queries to Insert, Update, Delete, and View Data Guide to Oracle 10g ITBIS373 Database Development.
9/29/2005From Introduction to Oracle:SQL and PL/SQL, Oracle 1 Restricting and Sorting Data Kroenke, Chapter Two.
Simple Queries DBS301 – Week 1. Objectives Basic SELECT statement Computed columns Aliases Concatenation operator Use of DISTINCT to eliminate duplicates.
Tarik Booker CS 122. What we will cover… Tables (review) SELECT statement DISTINCT, Calculated Columns FROM Single tables (for now…) WHERE Date clauses,
Retrieving Information Pertemuan 3 Matakuliah: T0413/Current Popular IT II Tahun: 2007.
Chapter 5 Introduction to SQL.
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Writing Basic SQL SELECT Statements
Basic select statement
LESSON 3.1a Database Administration Fundamentals Selecting Data.
Referential Integrity
Multiplying Matrices.
Relational Databases The Relational Model.
Relational Databases The Relational Model.
Querying Database ISYS 363.
Referential Integrity
SQL LANGUAGE and Relational Data Model TUTORIAL
Multiplying Matrices.
CSC 453 Database Systems Lecture
‘ORDER BY’ Order by clause allows sorting of query results by one or more columns. Sorting can be done in ascending or descending. Default order is ascending.
Multiplying Matrices.
Multiplying Matrices.
Multiplying Matrices.
MySQL SQL for MySQL (I) Salim Mail :
CSC 453 Database Systems Lecture
Introduction to SQL Server and the Structure Query Language
Presentation transcript:

select

select Att 1, Att 2, Att 3,…, Att n from Tablename where (condition) Order by att1,att2 |desc; //Order By (Ascending & Descending) Explanation: –condition will determine the row(s) which will be retrieved from the table. –If you want to select all the attributes from a table you can use all (*) operator.

Logical Operators NOT –Negation of the condition AND –The two conditions must be satisfied OR –The 1 st, the 2 nd or both of them must be satisfied

Logical Operation >, >=, between lowervalue and uppervalue –attribute/condition value lays in the closed interval [lowervalue,uppervalue] in (v 1,v 2,v 3, …, v n ) –attribute/condition value must match one value in the arches Like

select example select * from college; select Cid, Cname from college; select * from college where cid=10; select Cid, Cname from college where cid between 10 and 30; select Cid, Cname from college where cid in (10,30);

select from more than one table select T1.Att1, T1.Att2, T2.Att1,T2.Att2 from table1 T1, table2 T2 where (condition); Explanation: –Condition will determine which rows in the table1 related with table2

select example select T1.sid,T1.Sname, T2.cname from students T1, college T2 where T1.cid = T2.cid;

View benefits Create or replace view Std_view as select T1.sid,T1.Sname, T2.cname from students T1, college T2 where T1.cid = T2.cid;

Select from dual Select 1+3, sysdate from dual;

Alias Name Select att1 as “col-alias”, att2 as “col-alias”, att3 as “col-alias” From TableName Where (conditon) Order by att1 | col-alias; Notes: –As is optional. – “ ” bounded the column alias name is optional if your column alias name has no space, or special characters. –if the letter case is important.

Alias Name Select sid as “StudentID”, Sname “Student Name” From students Where sid >=20 Order by “StudentID”; Note: –Use can use the alias name with the “order by” phrase. –You can’t use the alias name with the “where” phrase.

Aggregation Functions The aggregation function return number value and ignore the null values. –Count(att_name) –Sum(att_name) –Max(att_name) –Min(att_name) –Avg(att_name)

example Select count(saverage),sum(saverage), sum(saverage)/count(saverage), avg(saverage) from students; Select college.cid,cname, avg(saverage) from students,college where students.cid=college.cid group by college.cid,cname;

Select From Where Group by Having Order by

Select college.cid,cname, avg(saverage) from students,college where students.cid=college.cid group by college.cid,cname having avg(saverage)> 80;

select * from students where cid = (select cid from students where sid=12345);