CHAPTER 34MySQL Views

Even relatively simplistic data-driven applications rely on queries involving several tables. For instance, suppose you want to create an interface that displays each employee's name, e-mail address, total number of absences, and bonuses. The query might look like this:

SELECT emp.employee_id, emp.firstname, emp.lastname, emp.email,        COUNT(att.absence) AS absences, COUNT(att.vacation) AS vacation,        SUM(comp.bonus) AS bonus FROM employees emp, attendance att, compensation comp WHERE emp.employee_id = att.employee_id AND emp.employee_id = comp.employee_id GROUP BY emp.employee_id ASC ORDER BY emp.lastname;

Queries of this nature are enough to send shudders down one's spine because of their size, particularly ...

Get Beginning PHP and MySQL: From Novice to Professional, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.