WEEK# 12 Haifa Abulaiha November 02,
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 2
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; 3
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; 4
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; 5
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.StudentID GROUP BY Students.FirstName, Students.LastName; 6
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 = “ ”; 7
SQL INSERT To insert a new record in a table in the database. Example: INSERT INTO Students VALUES (“Sarah”, “Joseph”, “ ”); INSERT INTO Students (FirstName, LastName, StudentID) VALUES (“Sarah”, “Joseph”, “ ”); 8
SQL UPDATE To update records in a table in the database. Example: Update StudentAddresses SET StudentAddresses.AddressType = “Mailing” WHERE StudentAddresses.AddressType=“Home”; 9
SQL DELETE To delete records from a table in the database. Example: DELETE FROM StudentAddresses WHERE StudentAddresses.AddressType=“Parent”; 10
IMPORTANT DATES Due MyITLab Lesson DMonday 11/02 Homework # 5Friday 11/06 Exam 2 Section 19Monday 11/09 Exam 2 Section 21Wednesday 11/11 MyITLab Bonus Project # 2Friday 11/13 MyITLab Lesson EMonday 11/16 11