Is it a good idea to join three or more tables together as in the following example. I’m trying to focus on performance. Is there any way to re-write this query that would be more efficient and faster performing? I’ve tried to make is as simplistic as possible.
select * from a
join b on a.id = b.id
join c on a.id = c.id
join d on c.id = d.id
where a.property1 = 50
and b.property2 = 4
and c.property3 = 9
and d.property4 = 'square'
Performance wise, I think it really depends on the number of records in each table, and making sure that you have the proper indexes defined. (I’m also assuming that
SELECT *is a placeholder; you should avoid wildcards)I’d start off by checking out your execution plan, and start optimizing there. If you’re still getting suboptimal performance, you could try using temp tables to break up the 4 table join into separate smaller joins.