Prev | Current Page 146 | Next

Emilian Balanescu and Cristian Darie

"Beginning PHP and MySQL E-Commerce: From Novice to Professional, Second Edition"


Unless a sorting order is specified, the order in which the rows are returned by a SELECT
clause can??™t be determined. Moreover, executing the same query twice could generate different
results! To sort the results, you use ORDER BY. The following query will return the list of
departments sorted alphabetically by the department name:
CHAPTER 4 ?–  CREATING THE PRODUCT CATALOG: PART 1 80
SELECT department_id, name, description
FROM department
ORDER BY name;
INSERT
The INSERT statement is used to insert a row of data into the table. Its syntax is as follows:
INSERT INTO [(column list)] VALUES (column values)
?– Tip Although the column list is optional (if you don??™t include it, column values are assigned to columns
in the order in which they appear in the table??™s definition), you should always include it. This ensures that
changing the table definition doesn??™t break the existing INSERT statements.
The following INSERT statement adds a department named Zodiac T-Shirts Department to
the department table:
INSERT INTO department (name) VALUES ('Zodiac T-Shirts Department');
No value was specified for the description field, because it was marked to allow NULLs in
the department table. This is why you can omit specifying a value, if you want to. Also, you??™re
allowed to omit specifying a department ID, because the department_id column was created
with the AUTO_INCREMENT option, which means the database takes care of automatically generating
a value for it when adding new records.


Pages:
134135136137138139140141142143144145 146 147148149150151152153154155156157158
gadżety reklamowewarszawa rehabilitacjawentylatory kanałowegry logiczne dla dziecibiuro ochrony