Database Reference
In-Depth Information
function keywords that are followed by parentheses should have them directly after the
keyword, without a space.
Notice also the name of the column at the top of Figure 6.14. This name is the CONCAT
function we issued within the query. Although this name makes it obvious what the column
is, if we had to continually refer to this within other queries or php code it would soon
become tedious. So here is a good example of using the AS keyword to give the results a dif-
ferent name:
SELECT
CONCAT(FirstName, “ “ , LastName) AS fullnames
FROM visitorbook
Figure 6.15 shows the results of just adding AS fullnames to our query. Our column now
has a meaningful name.
We can demonstrate this one step further. On our website we will eventually show visi-
tors all of the visitor book entries. We will probably have to format the data we get back
from the query extensively to make it fit for presentation on a webpage. This might require
much formatting within the scripting language that the page is written in. So we will use
the CONCAT function of SQL to do some of the formatting for us, saving some time and
work later on. Here is a sample script:
SELECT
CONCAT(“In our visitor book, “,
FirstName,
“ “ ,
LastName,
“ says: “,
Entrytext )
AS entries
FROM visitorbook
As the CONCAT has multiple elements here, I have over-formatted the script so you can
see what is happening. There are lots of commas and speech marks that can get quite con-
Figure 6.15
CONCAT and AS for readable results.
Search WWH ::




Custom Search