下面是需要Laravel查询的SQL查询。
INSERT INTO 'details' (id, contact)
SELECT DISTINCT tmp_details.id, students.contact
FROM 'tmp_details'
INNER JOIN 'students' USING(name)
ON CONFLICT DO NOTHING;
我无法应用ON CONFLICT
条件。
我已对其进行了部分转换,如下所示。
$strSQL = DB::table('tmp_details')
->join('students', 'tmp_details.name', '=', 'students.name')
->select('tmp_details.id','students.contact');
DB::table('details')->insertUsing(['id', 'contact'], $strSql);
答案 0 :(得分:0)
不确定,但是尝试一下。
$strSQL = DB::table('tmp_details')
->join('students', 'tmp_details.name', '=', 'students.name')
->pluck('tmp_details.id','students.contact');
DB::table('details')->insertOrIgnore($strSql);
答案 1 :(得分:0)
尝试使用DB::select()
语句:
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;
");