SELECT name FROM department WHERE department_id = 1;
?– Tip You can easily test these queries to make sure they actually work by using the MySQL console interface
or phpMyAdmin.
If you want more columns to be returned, you simply list them, separated by commas.
Alternatively, you can use an asterisk (*), which means ???all columns.??? However, for performance
reasons, if you need only certain columns, you should list them separately instead of
asking for them all. Using * is not advisable even if at a particular moment you do want all the
columns for a query, because in the future, you may add even more columns to the table, and
your query would end up asking for more data than is needed. Finally, using * doesn??™t guarantee
the order in which the columns are returned, as the order of the columns in a table may
change (although this is not likely to happen). For these reasons, we don??™t use * in this book.
With your current department table, the following two statements return the same results:
SELECT department_id, name, description
FROM department
WHERE department_id = 1;
SELECT * FROM department WHERE department_id = 1;
?– Tip You can split an SQL query on more lines, if you prefer??”MySQL won??™t mind.
If you don??™t want to place any condition on the query, simply remove the WHERE clause,
and you??™ll get all the rows. The following SELECT statement returns all rows and all columns
from the department table:
SELECT * FROM department;
?– Tip If you are impatient and can??™t wait until later in the chapter, you can test the SQL queries right now by
using the phpMyAdmin web client interface! Be careful, though, because in the rest of the book, we??™ll assume
the data in your department table is the same as shown previously in the chapter.
Pages:
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157