11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 34 • MYSQL VIEWSwww.it-ebooks.info+-----------------------------+| Tables_in_corporate |+-----------------------------+| employees || employee_contact_info_view |+-----------------------------+Now execute the DESCRIBE statement on the view:mysql>DESCRIBE employee_contact_info_view;This produces:+------------+-------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+------------+-------------+------+-----+---------+-------+| first_name | varchar(100) | NO | | | || last_name | varchar(100) | NO | | | || email | varchar(100) | NO | | | || phone | char(10) | NO | | | |+------------+-------------+------+-----+---------+-------+You might be surprised to know that you can even create views that are updatable. That is, you caninsert and even update rows by referencing the view, but result in the underlying table being updated.This feature is introduced in the “Updating Views” section.Customizing View ResultsA view isn’t constrained to return each row defined in the query that was used to create the view. Forinstance, it’s possible to return only the employees’ last names and e-mail addresses:SELECT last_name, email FROM employee_contact_info_view;This returns results similar to the following:+-----------+-------------------+| last_name | email |+-----------+-------------------+| Connors | bob@example.com || Gilmore | jason@example.com || Wade | matt@example.com |+-----------+-------------------+You can also override any default ordering clause when invoking the view. For instance, theemployee_contact_info_view view definition specifies that the information should be ordered accordingto last name. But what if you want to order the results according to phone number? Just change theclause, like so:662

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!