Tuesday, December 13, 2016

Methods of visualizing joins


Just wondering if anyone has any tricks (or tools) they use to visualize joins. You know, you write the perfect query, hit run, and after it's been running for 20 minutes, you realize you've probably created a cartesian join.
I sometimes have difficulty visualizing what's going to happen when I add another join statement and wondered if folks have different techniques they use when trying to put together lots of joins.
shareimprove this question
8 
Know your data, and know your joins - codinghorror.com/blog/2007/10/… – OMG Ponies Jul 30 '10 at 21:48
1 
@OMGPonies that's about the best answer to this I've thought of. – Matthew Jones Jul 30 '10 at 21:50

4 Answers

Always keep the end in mind.
  1. Ascertain which are the columns you need
  2. Try to figure out the minimum number of tables which will be needed to do it.
  3. Write your FROM part with the table which will give max number of columns. eg FROM Teams T
  4. Add each join one by one on a new line. Ensure whether you'll need OUTER, INNER, LEFT, RIGHT JOIN at each step.
Usually works for me. Keep in mind that it is Structured query language. Always break your query into logical lines and it's much easier.

No comments:

Post a Comment