week# 12 haifa abulaiha november 02, 2015 1
Post on 18-Jan-2018
214 Views
Preview:
DESCRIPTION
TRANSCRIPT
WEEK# 12
Haifa Abulaihahaifa.abulaiha@mail.wvu.eduNovember 02, 2015
1
2
SQL
• Structure Query Language.• SQL is a standard language to define,
manipulate and retrieve data in database.• Basic SQL keywords:
– SELECT– FROM– WHERE– ORDER BY
3
SQL SELECT• Select statement is used to retrieve data from
tables in a database.• Select specifies the fields to include in the query.• FROM key word specifies the tables where the
fields can be found.• Example:
SELECT Students.FirstName, Students.LastName FROM Students;
SELECT * FROM Students;
4
SQL ORDER BY
• Determines how the rows will be sorted.• Example:
SELECT * FROM Students ORDER BY Students.LastName, Students.FirstName;
SELECT * FROM Students ORDER BY Students.LastName DESC;
5
SQL JOIN
• To include results from multiple tables.• JOIN
– INNER– LEFT– Right
• Example:SELECT Students.FirstName, Students.LastName, StudentAddresses.Address,FROM Students INNER JOIN StudentAddresses ON Students.StudentID=StudentAddresses.StudentID;
6
SQL GROUP BY
• To calculate statistics• Example:
SELECT Students.FirstName, Students.LastName, Count (StudentAddresses.Address) AS CountOfAddressType FROM Students INNER JOIN StudentAddresses ON Students.StudentID=StudentAddresses.StudentIDGROUP BY Students.FirstName, Students.LastName;
7
SQL WHERE
• Sets the criteria that records must match to be included in the results.
• If the query does not include WHERE, the query will return all records.
• Example:SELECT Students.FirstName WHERE Students.ID = “123456789”;
8
SQL INSERT
• To insert a new record in a table in the database.
• Example:INSERT INTO Students VALUES (“Sarah”, “Joseph” , “123456789”);
INSERT INTO Students (FirstName, LastName, StudentID) VALUES (“Sarah”, “Joseph” , “123456789”);
9
SQL UPDATE
• To update records in a table in the database.
• Example:Update StudentAddresses SET StudentAddresses.AddressType = “Mailing” WHERE StudentAddresses.AddressType=“Home”;
10
SQL DELETE
• To delete records from a table in the database.
• Example:DELETE FROM StudentAddresses WHERE StudentAddresses.AddressType=“Parent”;
11
IMPORTANT DATESDue
MyITLab Lesson D Monday 11/02
Homework # 5 Friday 11/06
Exam 2 Section 19 Monday 11/09
Exam 2 Section 21 Wednesday 11/11
MyITLab Bonus Project # 2 Friday 11/13
MyITLab Lesson E Monday 11/16
top related