Содержание
- 2. In this Lecture SQL SELECT WHERE clauses SELECT from multiple tables JOINs For more information Connolly
- 3. SQL SELECT Overview SELECT [DISTINCT | ALL] FROM [WHERE ] [ORDER BY ] [GROUP BY ]
- 4. Example Tables
- 5. DISTINCT and ALL Sometimes you end up with duplicate entries Using DISTINCT removes duplicates Using ALL
- 6. WHERE Clauses Usually you don’t want all the rows A WHERE clause restricts the rows that
- 7. WHERE Examples SELECT * FROM Grade WHERE Mark >= 60 SELECT DISTINCT ID FROM Grade WHERE
- 8. WHERE Example Given the table Write an SQL query to find a list of the ID
- 9. One Solution SELECT ID, Mark FROM Grade WHERE (Code = ‘IAI’) AND (Mark >= 40)
- 10. SELECT from Multiple Tables Often you need to combine information from two or more tables You
- 11. SELECT from Multiple Tables SELECT First, Last, Mark FROM Student, Grade WHERE (Student.ID = Grade.ID) AND
- 12. SELECT from Multiple Tables ID First Last ID Code Mark S103 John Smith S103 DBS 72
- 13. SELECT from Multiple Tables ID First Last ID Code Mark S103 John Smith S103 DBS 72
- 14. SELECT from Multiple Tables ID First Last ID Code Mark S103 John Smith S103 DBS 72
- 15. SELECT from Multiple Tables First Last Mark John Smith 72 John Smith 58 Mary Jones 68
- 16. SELECT from Multiple Tables When selecting from multiple tables you almost always use a WHERE clause
- 17. SELECT from Multiple Tables Student Grade Course Student.ID = Grade.ID Course.Code = Grade.Code
- 18. JOINs JOINs can be used to combine tables There are many types of JOIN CROSS JOIN
- 19. CROSS JOIN SELECT * FROM Student CROSS JOIN Enrolment ID Name ID Code 123 John 123
- 20. NATURAL JOIN SELECT * FROM Student NATURAL JOIN Enrolment Code DBS PRG DBS PRG
- 21. CROSS and NATURAL JOIN SELECT * FROM A CROSS JOIN B is the same as SELECT
- 22. INNER JOIN INNER JOINs specify a condition which the pairs of rows satisfy SELECT * FROM
- 23. INNER JOIN SELECT * FROM Student INNER JOIN Enrolment USING (ID) ID Name ID Code 123
- 24. INNER JOIN SELECT * FROM Buyer INNER JOIN Property ON Price Name Budget Address Price Smith
- 25. INNER JOIN SELECT * FROM A INNER JOIN B ON is the same as SELECT *
- 26. JOINs vs WHERE Clauses JOINs (so far) are not needed You can have the same effect
- 27. Writing Queries When writing queries There are often many ways to write the query You should
- 28. This Lecture in Exams
- 29. This Lecture in Exams Find a list of all the CD titles. (1 mark) Find a
- 31. Скачать презентацию