LOGO 1 Lab_04: Basic SQL. 2 Outline  The ORDER BY Keyword  SQL ORDER BY Syntax  SQL NULL Values.

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

SQL Structured Query Language. SQL The SELECT Statement The SELECT statement is used to select data from a table. The tabular result is stored in a result.
Copyright © by Royal Institute of Information Technology Introduction To Structured Query Language (SQL) 1.
1ISM - © 2010 Houman Younessi Lecture 3 Convener: Houman Younessi Information Systems Spring 2011.
SELECT Advanced. Sorting data in a table The ORDER BY clause is used for sorting the data in either ascending or descending order depending on the condition.
CPS120: Introduction to Computer Science Information Systems: Database Management Nell Dale John Lewis.
LOGO 1 Lab_02: Basic SQL. 2 Outline  Database Tables  SQL Statements  Semicolon after SQL Statements?  SQL DML and DDL  SQL SELECT Statement  SQL.
15 Structured Query Language (SQL). 2 Objectives After completing this section, you should be able to: Understand Structured Query Language (SQL) and.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database systems.
INTERNET APPLICATION DEVELOPMENT PRACTICAL ON CONNECTING TO MYSQL.
Lecture6:Data Manipulation in SQL, Simple SQL queries Prepared by L. Nouf Almujally Ref. Chapter5 Lecture6 1.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
CPS120: Introduction to Computer Science Lecture 19 Introduction to SQL.
Structure Query Language SQL. Database Terminology Employee ID 3 3 Last name Small First name Tony 5 5 Smith James
ZEIT2301 Design of Information Systems SQL: Computing Statistics School of Engineering and Information Technology Dr Kathryn Merrick.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
SQL Unit – 2 Base Knowledge Presented By Mr. R.Aravindhan.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 DBS201: Introduction to Structure Query Language (SQL) Lecture 1.
SQL Basic. What is SQL? SQL (pronounced "ess-que-el") stands for Structured Query Language. SQL is used to communicate with a database.
SQL. คำสั่ง SQL SQL stands for Structured Query Language is a standard language for accessing and manipulating databases.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
Fox MIS Spring 2011 Database Week 5 SQL basics SELECT, INSERT, UPDATE, DELETE.
Lab_03: Basic SQL.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
CIS 375—Web App Dev II SQL. 2 Introduction SQL (Structured _______ Language) is an ANSI standard language for accessing databases.ANSI SQL can execute.
SQL Jan 20,2014. DBMS Stores data as records, tables etc. Accepts data and stores that data for later use Uses query languages for searching, sorting,
5. Simple SQL using Oracle1 Simple SQL using Oracle 5. Working with Tables: Data management and Retrieval 6. Working with Tables: Functions and Grouping.
1 SQL-2 Tarek El-Shishtawy Professor Ass. Of Computer Engineering.
CHAPTER 9 SQL อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา 1.
Session 9 Accessing Data from a Database. RDBMS and Data Management/ Session 9/2 of 34 Session Objectives Describe the SELECT statement, its syntax and.
INFANL01-3 ANALYSE 3 WEEK 3 March 2015 Institute voor Communication, Media en Informatietechnology.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
1 БАЗЫ ДАННЫХ. 2 ПРЕДЛОЖЕНИЯ SQL ВЫБОРКА - SELECT SELECT [предикат] { * | таблица.* | [таблица.]поле_1 [AS псевдоним_1] [, [таблица.]поле_2 [AS псевдоним_2]
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 5: SQL I Rob Gleasure robgleasure.com.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
به نام خدا SQL QUIZ جوانمرد Website: ejavanmard.blogfa.com.
ITS232 Introduction To Database Management Systems Siti Nurbaya Ismail Faculty of Computer Science & Mathematics, Universiti Teknologi MARA (UiTM), Kedah.
ADVANCED SQL.  The SQL ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by one or more columns.  The ORDER BY keyword sorts the.
Insert, Update, and Delete Statements DBMS Course.
Lec-7. The IN Operator The IN operator allows you to specify multiple values in a WHERE clause. SQL IN Syntax SELECT column_name(s) FROM table_name WHERE.
LEC-8 SQL. Indexes The CREATE INDEX statement is used to create indexes in tables. Indexes allow the database application to find data fast; without reading.
SQL Structured Query Language. SQL is an ANSI (American National Standards Institute) standard computer language for accessing and manipulating database.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
 MySQL is a database system used on the web  MySQL is a database system that runs on a server  MySQL is ideal for both small and large applications.
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
ORDER BY Clause The result of a query can be sorted in ascending or descending order using the optional ORDER BY clause. The simplest form of.
Fundamentals of DBMS Notes-1.
Web Systems & Technologies
MySQL DML Commands By Prof. B.A.Khivsara
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Introduction to Structured Query Language(SQL)
PHP + MySQL Commands Refresher.
SQL Tutorial.
Lecturer: Mukhtar Mohamed Ali “Hakaale”
CIS16 Application Programming with Visual Basic
Access: SQL Participation Project
Lesson Plan Instructional Objective Learning Objective
SQL.
Using CASE Value expression
Structured Query Language
កម្មវិធីបង្រៀន SQL Programming ជាភាសាខ្មែរ Online SQL Training Course
SQL NOT NULL Constraint
Presentation transcript:

LOGO 1 Lab_04: Basic SQL

2 Outline  The ORDER BY Keyword  SQL ORDER BY Syntax  SQL NULL Values

The ORDER BY Keyword  The ORDER BY keyword is used to sort the result-set by a specified column.  The ORDER BY keyword sort the records in ascending order by default.  If you want to sort the records in a descending order, you can use the DESC keyword.

SQL ORDER BY Syntax  SQL ORDER BY Syntax SELECT column_name(s) FROM table_name ORDER BY column_name(s) ASC|DESC

ORDER BY Example P_IdLastNameFirstNameAddressCity 1HansenOlaTimoteivn 10Sandnes 2SvendsonToveBorgvn 23Sandnes 3PettersenKariStorgt 20Stavanger 4NilsenTomVingvn 23Stavanger The "Persons" table: Now we want to select all the persons from the table above, however, we want to sort the persons by their last name.

ORDER BY Example  We use the following SELECT statement: SELECT * FROM Persons ORDER BY LastName P_IdLastNameFirstNameAddressCity 1HansenOlaTimoteivn 10Sandnes 4NilsenTomVingvn 23Stavanger 3PettersenKariStorgt 20Stavanger 2SvendsonToveBorgvn 23Sandnes The result-set will look like this:

ORDER BY DESC Example  Now we want to select all the persons from the table above, however, we want to sort the persons descending by their last name. P_IdLastNameFirstNameAddressCity 1HansenOlaTimoteivn 10Sandnes 2SvendsonToveBorgvn 23Sandnes 3PettersenKariStorgt 20Stavanger 4NilsenTomVingvn 23Stavanger The "Persons" table:

ORDER BY DESC Example P_IdLastNameFirstNameAddressCity 2SvendsonToveBorgvn 23Sandnes 3PettersenKariStorgt 20Stavanger 4NilsenTomVingvn 23Stavanger 1HansenOlaTimoteivn 10Sandnes We use the following SELECT statement: SELECT * FROM Persons ORDER BY LastName DESC The result-set will look like this:

SQL NULL Values  NULL values represent missing unknown data.  By default, a table column can hold NULL values.  This chapter will explain the IS NULL and IS NOT NULL operators.

SQL NULL Values  If a column in a table is optional, we can insert a new record or update an existing record without adding a value to this column. This means that the field will be saved with a NULL value.  NULL values are treated differently from other values.  NULL is used as a placeholder for unknown or inapplicable values.  Note: It is not possible to compare NULL and 0; they are not equivalent.

SQL Working with NULL Values P_IdLastNameFirstNameAddressCity 1HansenOla Sandnes 2SvendsonToveBorgvn 23Sandnes 3PettersenKari Stavanger Look at the following "Persons" table: Suppose that the "Address" column in the "Persons" table is optional. This means that if we insert a record with no value for the "Address" column, the "Address" column will be saved with a NULL value. How can we test for NULL values? It is not possible to test for NULL values with comparison operators, such as =,. We will have to use the IS NULL and IS NOT NULL operators instead.

SQL IS NULL LastNameFirstNameAddress HansenOla PettersenKari How do we select only the records with NULL values in the "Address" column? We will have to use the IS NULL operator: SELECT LastName,FirstName,Address FROM Persons WHERE Address IS NULL The result-set will look like this: Tip: Always use IS NULL to look for NULL values

SQL IS NOT NULL LastNameFirstNameAddress SvendsonToveBorgvn 23 How do we select only the records with no NULL values in the "Address" column? We will have to use the IS NOT NULL operator: SELECT LastName,FirstName,Address FROM Persons WHERE Address IS NOT NULL The result-set will look like this: