18.4.3 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.

Slides:



Advertisements
Similar presentations
Chapter 4 Joining Multiple Tables
Advertisements

 2003 Prentice Hall, Inc. All rights reserved. Chapter 22 – Database: SQL, MySQL, DBI and ADO.NET Outline 22.1 Introduction 22.2 Relational Database Model.
 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
1 Introduction to Web Application Introduction to Data Base.
CSCI 3328 Object Oriented Programming in C# Chapter 12: Databases and LINQ 1 Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
Exercise SELECT authorID, lastName FROM authors AuthorID FirstName
Java Database Connectivity (JDBC). Introduction Database –Collection of data DBMS –Database management system –Storing and organizing data SQL –Relational.
Chapter 5 Introduction to SQL. Structured Query Language = the “programming language” for relational databases SQL is a nonprocedural language = the user.
Intro to JDBC To effectively use Java Data Base Connectivity we must understand: 1.Relational Database Management Systems (RDBMS) 2.JDBC Drivers 3.SQL.
Relational DBs and SQL Designing Your Web Database (Ch. 8) → Creating and Working with a MySQL Database (Ch. 9, 10) 1.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
A CCESSING D ATABASES WITH JDBC CH 24 C S 442: A DVANCED J AVA P ROGRAMMING.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Introduction to Databases Chapter 7: Data Access and Manipulation.
 2003 Prentice Hall, Inc. All rights reserved. 1 Java Database Connectivity with JDBC TM.
CIS 270—Application Development II Chapter 25—Accessing Databases with JDBC.
CHAPTER 8 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
Database: SQL and MySQL
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
1 Databases November 15, 2005 Slides modified from Internet & World Wide Web: How to Program (3rd) edition. By Deitel, Deitel, and Goldberg. Published.
 2004 Prentice Hall, Inc. All rights reserved. 1 Segment – 6 Web Server & database.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 4Introduction to Oracle9i: SQL1 Chapter 4 Joining Multiple Tables.
Java How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
DAT602 Database Application Development Lecture 3 Review of SQL Language.
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.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
Internet & World Wide Web How to Program, 5/e. © by Pearson Education, Inc. All Rights Reserved. 2 Revised by Dr. T. Tran for CSI3140.
Database UpdatestMyn1 Database Updates SQL is a complete data manipulation language that can be used for modifying the data in the database as well as.
 2005 Pearson Education, Inc. All rights reserved Accessing Databases with JDBC.
 2008 Pearson Education, Inc. All rights reserved Database: SQL, MySQL, ADO.NET 2.0 and Java DB.
 2001 Prentice Hall, Inc. All rights reserved. 1 Chapter 22 - SQL, MySQL, DBI and ADO Outline 22.1 Introduction 22.2 Relational Database Model 22.3 Relational.
 2009 Pearson Education, Inc. All rights reserved Databases and LINQ to SQL.
Database: SQL, MySQL, LINQ and Java DB © by Pearson Education, Inc. All Rights Reserved.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
LINQ to DATABASE-2.  Creating the BooksDataContext  The code combines data from the three tables in the Books database and displays the relationships.
COM621: Advanced Interactive Web Development Lecture 11 MySQL – Data Manipulation Language.
IFS180 Intro. to Data Management Chapter 10 - Unions.
 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.
SQL SQL Ayshah I. Almugahwi Maryam J. Alkhalifa
Database, SQL and ADO.NET
Web Systems & Technologies
CHAPTER 7 DATABASE ACCESS THROUGH WEB
Chapter 5 Introduction to SQL.
 2012 Pearson Education, Inc. All rights reserved.
Basic select statement
Introduction to Structured Query Language(SQL)
Accessing Databases with JDBC
LINQ to DATABASE-2.
JDBC.
Databases Intro (from Deitel)
Structured Query Language (SQL) William Klingelsmith
Chapter 7 Working with Databases and MySQL
Chapter 8 Working with Databases and MySQL
Databases - בסיסי נתונים
Chapter 22 - SQL, MySQL, DBI and ADO
Chapter # 7 Introduction to Structured Query Language (SQL) Part II.
LINQ to DATABASE-2.
Access: SQL Participation Project
Introduction To Structured Query Language (SQL)
MySQL Database System Installation Overview SQL summary
MySQL Database System Installation Overview SQL summary
Manipulating Data Lesson 3.
Java Chapter 6 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

18.4.3 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 an ORDER BY clause is SELECT columnName1, columnName2, … FROM tableName ORDER BY column ASC SELECT columnName1, columnName2, … FROM tableName ORDER BY column DESC where ASC specifies ascending order, DESC specifies descending order and column specifies the column on which the sort is based. The default sorting order is ascending, so ASC is optional. Multiple columns can be used for ordering purposes with an ORDER BY clause of the form ORDER BY column1 sortingOrder, column2 sortingOrder, … The WHERE and ORDER BY clauses can be combined in one query. If used, ORDER BY must be the last clause in the query. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

SELECT AuthorID, FirstName, LastName FROM Authors ORDER BY LastName ASC ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

SELECT AuthorID, FirstName, LastName FROM Authors ORDER BY LastName DESC ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

SELECT AuthorID, FirstName, LastName FROM Authors ORDER BY LastName ASC, FirstName ASC ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

SELECT ISBN, Title, EditionNumber, CopyRight FROM Titles WHERE Title LIKE ‘%How to Program’ ORDER BY Title ASC ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.4.4 Merging Data from Multiple Tables: INNER JOIN An INNER JOIN operator merges rows from two tables by matching values in columns that are common to the tables. The basic form for the INNER JOIN operator is: SELECT columnName1, columnName2, … FROM table1 INNER JOIN table2 ON table1.columnName = table2.columnName The ON clause of the INNER JOIN specifies the columns from each table that are compared to determine which rows are merged. The following query produces a list of authors accompanied by the ISBNs for books written by each author: SELECT FirstName, LastName, ISBN FROM Authors INNER JOIN AuthorISBN ON Authors.AuthorID = AuthorISBN.AuthorID ORDER BY LastName, FirstName ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.4.4 Merging Data from Multiple Tables: INNER JOIN (Cont.) Note the use of the syntax tableName.columnName in the ON clause. This syntax, called a qualified name, specifies the columns from each table that should be compared to join the tables. The “tableName.” syntax is required if the columns have the same name in both tables. The same syntax can be used in any SQL statement to distinguish columns in different tables that have the same name. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.4.5 INSERT Statement An INSERT statement inserts a new row into a table. The basic form of this statement is INSERT INTO tableName ( columnName1, columnName2, …, columnNameN ) VALUES ( value1, value2, …, valueN ) where tableName is the table in which to insert the row. The tableName is followed by a comma-separated list of column names in parentheses. The list of column names is followed by the SQL keyword VALUES and a comma-separated list of values in parentheses. Always explicitly list the columns when inserting rows. If the table’s column order changes or a new column is added, using only VALUES may cause an error. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.4.5 INSERT Statement (Cont.) The INSERT statement INSERT INTO Authors ( FirstName, LastName ) VALUES ( 'Sue', 'Red' ) inserts a row into the Authors table. The statement indicates that values are provided for the FirstName and LastName columns. The corresponding values are 'Sue' and ‘Red'. We do not specify an AuthorID in this example because AuthorID is an autoincremented column. For every row added to this table, the DBMS assigns a unique AuthorID value that is the next value in the autoincremented sequence (i.e., 1, 2, 3 and so on). In this case, Sue Red would be assigned AuthorID number 6. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.4.6 UPDATE Statement An UPDATE statement modifies data in a table. Its basic form is UPDATE tableName SET columnName1 = value1, columnName2 = value2, …, columnNameN = valueN WHERE criteria where tableName is the table in which to update data. The tableName is followed by keyword SET and a comma-separated list of column name/value pairs in the format columnName = value. The optional WHERE clause criteria determines which rows to update. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

UPDATE Authors SET LastName = ‘Black’ WHERE AuthorID = 6 ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.4.7 DELETE Statement A SQL DELETE statement removes rows from a table. Its basic form is DELETE FROM tableName WHERE criteria where tableName is the table from which to delete a row (or rows). The optional WHERE criteria determines which rows to delete. If this clause is omitted, all the table’s rows are deleted. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

DELETE FROM Authors WHERE AuthorID = 6 ©1992-2012 by Pearson Education, Inc. All Rights Reserved.

18.5 MySQL MySQL (pronounced “my sequel”) is a robust and scalable relational database management system (RDBMS) that was created by the Swedish consulting firm TcX in 1994. MySQL, now owned by Oracle, is a multiuser, multithreaded RDBMS server that uses SQL to interact with and manipulate data. Multithreading capabilities enable MySQL database to perform multiple tasks concurrently, allowing the server to process client requests efficiently. Implementations of MySQL are available for Windows, Mac OS X, Linux and UNIX. ©1992-2012 by Pearson Education, Inc. All Rights Reserved.