Database Reference
In-Depth Information
Figure 6.16
CONCAT supports complex formatting.
fusing, so have a look at the results in Figure 6.16 to see what it does. Now that you've
viewed the results, the script should make more sense.
So you can see how you can use CONCAT to format your query's output, getting SQL to
do the work for you to save scripting time later on. You can put multiple elements inside the
CONCAT function. Also remember that you are not limited to using just a CONCAT func-
tion in a select statement, you can also use other column names at the same time, for exam-
ple:
SELECT
CONCAT(FirstName, “ “ , LastName) AS names, EntryID, Entrytext
FROM visitorbook
Before running this script, see if you can work out what results it will produce.
ORDER BY
One of the things that you often wish to do with databases is sort the results. MySQL sorts
tables using the ORDER BY clause in the following format:
SELECT columnnames
FROM visitorbook
ORDER BY columnnames
For example, to sort all of our visitorbook entries by last name we would run:
SELECT entryid, lastname
FROM visitorbook
ORDER BY lastname
Figure 6.17 shows the results of this query. Notice how the rows have been returned in a
different order to which they were created.
Search WWH ::




Custom Search