Database Reference
In-Depth Information
New Term
Field Essentially means the same thing as
column
and often is used interchangeably,
although database columns are typically called
columns
and the term
fields
is normally
used in conjunction with calculated fields.
It is important to note that only the database knows which columns in a
SELECT
statement are actual table columns and which are calculated fields.
From the perspective of a client (for example, your application), a calculated
field's data is returned in the same way as data from any other column.
Tip
Client Versus Server Formatting Many of the conversions and reformatting that can
be performed within SQL statements can also be performed directly in your client appli-
cation. However, as a rule, it is far quicker to perform these operations on the database
server than it is to perform them within the client because DBMSs are built to perform
this type of processing quickly and efficiently.
To demonstrate working with calculated fields, let's start with a simple
example—creating a title made up of two columns.
The
vendors
table contains vendor name and address information. Imagine
you are generating a vendor report and need to list the vendor location as part
of the vendor name in the format
name (location)
.
The report wants a single value, and the data in the table is stored in two col-
umns:
vend_name
and
vend_country
. In addition, you need to surround
vend_country
with parentheses, and those are definitely not stored in the
database table. The
SELECT
statement that returns the vendor names and loca-
tions is simple enough, but how would you create this combined value?
New Term
Concatenate Joining values together (by appending them to each other) to form a
single long value.
The solution is to concatenate the two columns. In MariaDB
SELECT
state-
ments, you can concatenate columns using the
Concat()
function.
Tip
MariaDB Is Different Most DBMSs use operators
+
or
||
for concatenation; MariaDB
(like MySQL) uses the
Concat()
function. Keep this in mind when converting SQL
statements to MariaDB (and MySQL).