Question: I want to create a table employee with id,name,dept,username attributes. 

The id column values are auto\_increment. I want to concatenate the values of id with dept to generate the username.

Following is the query that I wrote:
create table employee emp\_id MEDIUMINT NOT NULL AUTO\_INCREMENT, name char(30) NOT NULL, dept char(6)NOT NULL, username varchar NOT NULL PRIMARY KEY(emp\_id);

How to insert values into this table properly? Please help.

Answer: 
If your usernames will always be the concatenation of `id` and `dept`, you don't need to create a separate column for it, you can just select it using the MySQL [CONCAT](http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_concat) function, like this:

```
SELECT id, name, dept, CONCAT(id, '-', dept) AS username FROM employee

```

This will return results for `username` like `13-sales`.

If you want to actually store the username (maybe because you want the ability to customize it later), you'll have to first insert the row to get the id, and then update the row setting the username to the concatenated id and dept.
You can use null on MySQL for auto traslate as the last id:

```
INSER INTO employee (name, dept) VALUES (?,?);
UPDATE employee SET username = concant(emp_id,dept) WHERE emp_id = NULL; 

```