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

Selecting Data

Now that the database has some records in it, you can begin to retrieve the information with the most used of all SQL terms, SELECT. This type of query returns rows of records that match certain criteria, using the syntax

SELECT which_columns FROM which_table
				

The simplest SELECT query is

SELECT * FROM tablename
				

The asterisk means that you want to view every column. Your other choice would be to specify the columns to be returned, with each separated from the next by a comma.

SELECT user_id, first_name, last_name
→ FROM users

There are a few benefits to being explicit about which columns are selected. The first is performance: There’s no reason to fetch columns you will not be using. The second is order: You can return columns ...

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