mysql computed field

Hello,

I'm not sure if i can do this, but is it possible to make a computed field in mysql, like say for instance I want to have a field called fullname which will automaticaly create a users full name from the field firstname and lastname. Also, if this is possible is it possible to have computed fields between tables, like say for instance i have a table for a customers quotes, with a dollar amount, and then i have another table called customerTotals which gives the customers total dollar amount of quotes for the year, is it possible to have this total dollar amount of quotes for the year field calculated even tho they are in different tables?

Thanks!

- Loren
LVL 4
LTY83Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
psadacConnect With a Mentor Commented:
for the first question, yes :

SELECT CONCAT_WS(' ', firstname, lastname) AS fullname
FROM customers

for the second question probably yes but i don't have your table structure. it should be something like this :

SELECT CONCAT_WS(' ', c.firstname, c.lastname) AS fullname, ct.amout, SUM(cq.quotes) AS yearquotes
FROM customers AS c INNER JOIN customertotal AS ct ON c.customerid = ct.customerid
                                 INNER JOIN customerquotes AS cq ON (c.customerid = cq.customerid AND ct.year = cq.year)
GROUP BY cq.customerid, cq.year
 
0
 
alskdj80Commented:
i dont think this is possible... mysql is just storage, i dont think it has these features

if im wrong, someone plz correct me... this sounds rather interesting if it does exist
0
 
LTY83Author Commented:
but can this be done in the table automatically, IE: data is entered thru asp/sql but in the table the full name field generates itself?
0
 
psadacCommented:
yes, you can update a field with a computed expression :

UPDATE customer SET fullname = CONCAT_WS(' ', firstname, lastname)
WHERE fullname IS NULL
0
All Courses

From novice to tech pro — start learning today.