I have a query like below:
select
a.id, a.title, a.description
from
my_table_name as a
where
a.id in (select id from another_table b where b.id = 1)
My question is, is there any way I can avoid the subquery in where clause and use it in from clause itself without compromising of performance?
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `another_table` ADD INDEX `another_table_idx_id` (`id`);
SELECT
a.id,
a.title,
a.description
FROM
my_table_name AS a
WHERE
EXISTS (
SELECT
1
FROM
another_table b
WHERE
(
b.id = 1
)
AND (
a.id = b.id
)
)