如何使用连接进行插入

时间:2016-05-08 00:00:15

标签: mysql

我想取这个结果

SELECT * FROM `orgs`
WHERE `slug` = 'foo'

并将其用于此

INSERT INTO `projects-permissions` 
(`id`, `project`, `org`) 
VALUES 
(NULL, 'foo', ORG.ID)

3 个答案:

答案 0 :(得分:1)

public function getData() {
//$term =  Request::input('auto', 'r');
$results = [['firstname' => 'Edwardo', 'ID' => '12'], ['firstname' => 'Edwarda', 'ID' => '13']];
//$results = \DB::table('atp_players')->select('firstname')->get();

$data = array();

foreach($results as $result) {

     if(strpos($result,$term) !== false) {
        $temp = array();
        // This is what will be displayed by autocomplete
        $temp['label'] = $result->firstname;
        // This will be the value you get back through form (eg: User_ID)
        $temp['value'] = $result->ID;
        array_push($data, $temp);
    }
}
return Response::json($data);

或更短

INSERT INTO `projects-permissions` (`id`, `project`, `org`) 
SELECT NULL, 'foo', ID 
FROM `orgs`
WHERE `slug` = 'foo'

答案 1 :(得分:1)

if (key){//Your code here }

答案 2 :(得分:1)

INSERT INTO List<T>projects-permissionsidproject) SELECT null,slug,org FROM org 在哪里orgs =“foo”;