Skip to content

Commit 766a576

Browse files
committed
Update queries.md
1 parent 47f92ca commit 766a576

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

queries.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,6 +846,12 @@ The `insertOrIgnore` method will ignore errors while inserting records into the
846846

847847
> {note} `insertOrIgnore` will ignore duplicate records and also may ignore other types of errors depending on the database engine. For example, `insertOrIgnore` will [bypass MySQL's strict mode](https://dev.mysql.com/doc/refman/en/sql-mode.html#ignore-effect-on-execution).
848848
849+
The `insertUsing` method will insert new records into the table using a subquery. In the example below, we want to copy the users to a table before pruning.
850+
851+
DB::table('pruned_users')->insertUsing([
852+
'id', 'name', 'email', 'email_verified_at'
853+
], DB::table('users')->select('id', 'name', 'email', 'email_verified_at')->where('updated_at', '<=', now()->subMonth()));
854+
849855
<a name="auto-incrementing-ids"></a>
850856
#### Auto-Incrementing IDs
851857

0 commit comments

Comments
 (0)