-2

I want to implement the attribute "name". this attribute consists of the 2 other attributes "firstname" and "lastname".

my code:

firstname VARCHAR (30),
lastname VARCHAR (30),
name VARCHAR (firstname, lastname)

but i get the error that the syntax is not correct. so what is the right way to do it?

1 Answers1

0

MySQL doesn't automatically allow you to have a column that contains data from other columns (why duplicate data?). If this is what you want, I would suggest that you setup a view. Your base table would just contain the firstname and lastname, and then your view would return the firstname/lastname combination.

However, that's fairly redundant. I don't know what purpose you have for wanting a merged "name" column, but you could just return that directly with a select statement that uses the concat function.

select
    name = concat(firstname, " ", lastname),
    firstname, lastname
from
    my_table
RToyo
  • 2,877
  • 1
  • 15
  • 22