INSERT...SELECT in MySQL: Copying Rows Between Tables
Copying rows from one table into another as a SELECT-then-loop-INSERT operation means one query per row — INSERT...SELECT does the whole copy as a single statement, entirely inside the database.
TOPIC
Copying rows from one table into another as a SELECT-then-loop-INSERT operation means one query per row — INSERT...SELECT does the whole copy as a single statement, entirely inside the database.
MySQL and PostgreSQL both support indexing and querying inside a JSON column directly — Eloquent exposes that through arrow syntax and dedicated whereJson* methods, without raw SQL.
A loop of individual ->save() calls means one query per row — insert() (or upsert() for a merge) does it in one, at the cost of skipping model events and timestamps unless handled manually.
Every Eloquent timestamp is already a Carbon instance — the part that actually causes bugs is timezone handling: what gets stored, what gets displayed, and where the conversion between them should happen.
toSql(), getBindings(), and DB::listen() — the difference between seeing the query shape and seeing the actual query that ran, bindings included.
count(), isEmpty(), isNotEmpty(), and the N+1-query mistake people make trying to "optimize" an empty check on an Eloquent relationship.
PDO is the modern, framework-agnostic way to talk to MySQL from plain PHP — and prepared statements aren't optional if user input touches the query.
withTrashed(), onlyTrashed(), and restore() — plus the query-scope gotcha that makes soft-deleted rows silently vanish from relationships by default.
whereDate, whereBetween, and raw Carbon comparisons in Eloquent — which one to use and the timezone mistake that causes off-by-one-day bugs.
leftJoin() syntax, why it returns null columns instead of dropping rows, and the specific case where it behaves differently from a whereHas() relationship query.