Database Reference
In-Depth Information
INSERT INTO visitorbook
(CookieID,EntryDate,FirstName,MiddleName,LastName,EntryText)
VALUES (1, “2002-01-22”,“Rowan”,“”,“Norman”,“Just testing!”),
(1, “2002-02-01”,“Reuben”,“”,“Norman”,“I dont know what to type”),
(1, “2002-02-01”,“Pat”,“”,“Shah”,“Thought I would leave a message”),
(1, “2002-02-05”,“Lucy”,“”,“Garrett”,“Where has Princess gone?”),
(1, “2002-02-15”,“Zephen”,“”,“”,“I like the site but what about graphics”),
(1, “2002-02-16”,“Matthew”,“”,“Norman”,“Just testing!”);
You may notice that, for speed, we have used the TEXT datatype for most of the columns.
This is not very efficient but we will remedy this in a later chapter. Just create the table as it
is for now. Once you have populated the visitorbook table, check your work with:
SELECT *
FROM
visitorbook
This should give you six rows if you have copied the script in correctly. Now we will use
CONCAT to merge the firstname and lastname tables into one column. Execute the follow-
ing:
SELECT
CONCAT(FirstName, “ “ , LastName)
FROM visitorbook
This query says: “Give me the firstname, a space, and the lastname all in one column, for
every row in the visitorbook.” Each element inside the CONCAT parentheses is separated
by commas. If you have to include a string, such as the space character, then you need to
surround it with quotation marks. Figure 6.14 shows the results of this query; all names are
displayed neatly in a single column, with a space in between.
If you don't have results as shown in Figure 6.14, it is probably because you have put a
space in between the CONCAT keyword and the parentheses. CONCAT is a function, and all
Figure 6.14
CONCAT formats your results.
Search WWH ::




Custom Search