Php 在Laravel中SELECT语句之后插入记录时,如何应用“冲突”条件?
下面是需要Laravel查询的SQL查询 插入“详细信息”id,联系人 选择不同的tmp_details.id、students.contact 来自“tmp_详细信息” 使用名称内部连接“学生” 在冲突上无所作为; 我不能在冲突情况下申请 我已将其部分转换如下 $strSQL=DB::表“tmp\U详细信息” ->加入'students','tmp_details.name','=','students.name' ->选择'tmp_details.id'、'students.contact'; DB::table'details'->插入['id','contact'],$strSql; 不确定,但试试这个 尝试使用DB::select语句:Php 在Laravel中SELECT语句之后插入记录时,如何应用“冲突”条件?,php,laravel,lumen,Php,Laravel,Lumen,下面是需要Laravel查询的SQL查询 插入“详细信息”id,联系人 选择不同的tmp_details.id、students.contact 来自“tmp_详细信息” 使用名称内部连接“学生” 在冲突上无所作为; 我不能在冲突情况下申请 我已将其部分转换如下 $strSQL=DB::表“tmp\U详细信息” ->加入'students','tmp_details.name','=','students.name' ->选择'tmp_details.id'、'students.contact'
DB::select("
INSERT INTO 'details' (id, contact)
SELECT DISTINCT tmp_details.id, students.contact
FROM 'tmp_details'
INNER JOIN 'students' USING(name)
ON CONFLICT DO NOTHING;
");
不确定,但请尝试InsertOrgNore。我尝试使用InsertOrgNore,但出现如下错误:SQLSTATE[42703]:未定义列:7错误:关系详细信息的列0不存在第1行:插入详细信息0,1值$1,$2冲突…^SQL:在详细信息0中插入1个值id,冲突时联系人不显示查询。DB::table'details'->insertOrIgnore['id','contact'],$strSql//relapced only insertUsing我无法插入记录,可能是参数必须是数组,并且值不应在变量中给出。我将研究现成的解决方案:
DB::select("
INSERT INTO 'details' (id, contact)
SELECT DISTINCT tmp_details.id, students.contact
FROM 'tmp_details'
INNER JOIN 'students' USING(name)
ON CONFLICT DO NOTHING;
");