I am converting a piece of database SQL query to Laravel Eloquent query but it doesn't work.
My code snippet looks like this:
SELECT user_id FROM posts WHERE user_id NOT IN (SELECT id FROM users)
Can someone explain why?
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `users` ADD INDEX `users_idx_id` (`id`);
SELECT
posts.user_id
FROM
posts
WHERE
NOT EXISTS (
SELECT
1
FROM
users
WHERE
(
posts.user_id = users.id
)
)