Reagen,
Your question is more practical, and depends on what you want as an output.
Please refer to
this link which is from the
Categorized Questions and Answers page.
Your basic queries should be answered there. Otherwise, come back here and let us know your specific inputs and outputs and we'll provide you with one of many possible solutions.
Have Fun.