[eluser]srpurdy[/eluser]
[quote author="ggoforth" date="1261796255"]I'm still a little confused as to what your trying to accomplish, but I can explain how a left join works, and when you would use it. Lets say you had two tables, "parents" and "kids".
Every record in the parents table would represent one person, and every record in the kids table would represent one kid that's tied to a parent through the parent id. Lets say you wanted one query that selected a parent and their kids. So you write a query like:
SELECT * FROM parents JOIN kids ON parents.parent_id = kids.parent_id WHERE parents.parent_id = 1;
This would select a parent and their kids. The only problem is, what if this parent didn't have any kids (for some reason, I know they wouldn't be a parent if they didn't have kids, but just roll with me
. This query would not return any results, because there were no kids to join with the parent.
So, if you want to join two or more tables, but your not sure that the field your joining on exists in your other tables, you use left join. This in a round about way says, join these tables, and return the result, even if there is nothing to join with. We could rewrite the query above as such:
SELECT * FROM parents LEFT JOIN kids ON parents.parent_id = kids.parent_id WHERE parents.parent_id = 1;
So basically, give me everything from the table on the left (parents) even if it can not join on anything in the kids table.
I hope I didn't over complicate this, but that's basically how the LEFT JOIN works.
Greg[/quote]
Hi Greg,
Thanks for your reply. Way you explained it was good.
Using your above example I guess what I'm trying to do is the following.
Championship_Standing - Parent
- Series - Child of Standings
- Events - Child of Series
- Results_data - Child of Events
- Points Table - Child of Results_data
Its a big family lol
The key field in this case would be series_id that links them all together. In the case of Championship standings it needs to figure out what events are a part of whatever series and calculate the points from each event in a nutshell.
There could be 100 series, with thousands of events. but one series could have say 10 events. So the Championship Standings should display the totals based on those 10 events only.
Hope thats a little more clear. But your description of left join has helped me a bit. Hopefully I can come up with something in the meantime lol.
Shawn