INSERT SELECT MAX与文本连接

时间:2013-05-28 23:21:06

标签: mysql select insert max

我想从其他表中插入字段max id,但我需要将其与文本信息连接为“已创建新用户id =”MAX(my_employee.id)。有效的代码,但只插入id:

INSERT INTO my_logs (user_id, type, date) 
        SELECT '1', MAX(my_employee.id), '2013-05-28 23:52:07' FROM my_employee

我试过了:

INSERT INTO my_logs (user_id, type, date) 
          SELECT '1',"Created new user with id =" MAX(my_employee.id), 
                              '2013-05-28 23:52:07' FROM my_employee

和类似但似乎没有任何作用

2 个答案:

答案 0 :(得分:1)

这应该适合你:

insert into my_logs  
select 1, concat('Created new user with id = ', MAX(id)), '2013-05-28 23:52:07' 
from my_employee

答案 1 :(得分:1)

你想这样做吗?

INSERT INTO my_logs (user_id, type, date) 
      SELECT '1', concat('Created new user with id =', MAX(my_employee.id)), 
             '2013-05-28 23:52:07'
      FROM my_employee;