Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 LEFT join or INNER join

Author  Topic 

insanepaul
Posting Yak Master

178 Posts

Posted - 2010-11-12 : 10:18:54
When you join tables what goes through your mind when you consider it should be a LEFT join or INNER join in a professional environment? What are the steps?

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-12 : 10:37:20
Depends on what you want to accomplish.

If I know I want all the data from one table, regardless of anything else, the other tables are left joins. This is for "informational display". If I'm actually filtering records out based on specific qualifiers, it's an inner join.

First step is to identify your "base" table. Seems easy, but it's not always the most obvious.
Go to Top of Page

insanepaul
Posting Yak Master

178 Posts

Posted - 2010-11-12 : 10:44:39
quote:
Originally posted by TimSman

Depends on what you want to accomplish.

If I know I want all the data from one table, regardless of anything else, the other tables are left joins. This is for "informational display". If I'm actually filtering records out based on specific qualifiers, it's an inner join.

First step is to identify your "base" table. Seems easy, but it's not always the most obvious.



Yeah, that was the next question I was going to ask. Which table does one start off with
Go to Top of Page

TimSman
Posting Yak Master

127 Posts

Posted - 2010-11-12 : 10:56:02
I'd say it depends on a lot of factors. What are you trying to accomplish? What's your basic architecture? Are there aggregates? I'd say all of that weighs in. And if you don't like the way things are going, go back and start over.
Go to Top of Page

insanepaul
Posting Yak Master

178 Posts

Posted - 2010-11-12 : 11:11:42
quote:
Originally posted by TimSman

I'd say it depends on a lot of factors. What are you trying to accomplish? What's your basic architecture? Are there aggregates? I'd say all of that weighs in. And if you don't like the way things are going, go back and start over.


For a novice like me then it's very difficult to know what table to begin with without having some rules. I'm thinking that the base table is where most of the columns you want. Lets say 5 from table A and 1 or 2 each from all the other tables. What do you mean by basic architecture? What are aggregates in SQL? Are they dictionary tables? Does the size of the table matter? If table A connects 1-1 to 5 other tables then should that be the one to start with? Does it really matter which one we start with as they are all linked or does it affect performance by choosing the right one.
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2010-11-14 : 01:15:12
u can also go with inner join when u want to eliminate null records.if iam not wrong.
Go to Top of Page

jessiefun
Starting Member

35 Posts

Posted - 2010-11-15 : 01:20:50
Yeah, I agree with Tim. And now you need is to create two tables and make some practice. Then you will totally understand.
Good luck.
Regards, Jessie
Go to Top of Page
   

- Advertisement -