从另一个表和独立值插入表中

时间:2013-07-23 01:20:49

标签: mysql sql sql-insert nested-queries

说我有两张桌子,

Employee
name address phone phone_type

EmployeeContacts
name address phone

因此,我可以这样做:

INSERT INTO Employee name, address, phone VALUES(SELECT name, address, phone from EmployeeContacts where name = "Joe") and phoneType = "mobile"

基本上,插入从一个表中选择的某些值并插入一个额外的值?

如果没有,我该怎么做?

1 个答案:

答案 0 :(得分:2)

您想使用insert . . . select表单:

INSERT INTO Employee(name, address, phone, phonetype)
    SELECT name, address, phone, 'mobile'
    from EmployeeContacts
    where name = 'Joe'