O'Reilly logo

PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second Edition by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Grouping Selected Results

In the preceding chapter, two different clauses—ORDER BY and LIMIT—were introduced as ways of affecting the returned results. The former dictates the order in which the selected rows are returned; the latter dictates which of the selected rows are actually returned. This next clause, GROUP BY, is different in that it works by grouping the returned data into similar blocks of information. For example, to group all of the URLs by category, you would use

SELECT * FROM url_associations, urls
→ WHERE url_associations.url_id=urls.
→ url_id GROUP BY url_category_id

The returned data is altered in that you’ve now aggregated the information instead of returned just the specific itemized records. So where you might have seven ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required