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 ...
Get PHP and MySQL for Dynamic Web Sites: Visual Quickpro Guide, Second 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.