week# 12 haifa abulaiha november 02, 2015 1
DESCRIPTION
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; 3TRANSCRIPT
![Page 2: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/2.jpg)
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
![Page 3: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/3.jpg)
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;
![Page 4: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/4.jpg)
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;
![Page 5: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/5.jpg)
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;
![Page 6: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/6.jpg)
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;
![Page 7: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/7.jpg)
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”;
![Page 8: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/8.jpg)
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”);
![Page 9: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/9.jpg)
9
SQL UPDATE
• To update records in a table in the database.
• Example:Update StudentAddresses SET StudentAddresses.AddressType = “Mailing” WHERE StudentAddresses.AddressType=“Home”;
![Page 10: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/10.jpg)
10
SQL DELETE
• To delete records from a table in the database.
• Example:DELETE FROM StudentAddresses WHERE StudentAddresses.AddressType=“Parent”;
![Page 11: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/11.jpg)
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
![Page 12: WEEK# 12 Haifa Abulaiha November 02, 2015 1](https://reader035.vdocuments.us/reader035/viewer/2022062906/5a4d1b357f8b9ab05999cc1f/html5/thumbnails/12.jpg)