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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 too many records

Author  Topic 

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-11-16 : 16:22:03
I understand joining tables give all rows because of matching. the following gives me 705 rows. But as soon as I add sa.FromAirport, sa.ToAirport , the nubmer of rows jump to 1750. How can re-write this and still get 705 records with column from sa?

X002548
Not Just a Number

15586 Posts

Posted - 2009-11-16 : 16:25:05
You do understand that tables have relationships, just like a parent has to their Child?

For Example, I am a father, or 1 row in the Parent Table

I happen to have 3 children, or 3 rows in the Child table

If I only Select from the parent table looking for me, I get 1 row

If I then Join to the child table ON me, then the result would be 3 rows?

Understand?



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-11-16 : 16:26:23
Brett, So the query is good. hmm. what is this link (http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=129836) talking about
Go to Top of Page

doran_doran
Posting Yak Master

179 Posts

Posted - 2009-11-16 : 16:56:48
This works...

SELECT DISTINCT
a.event, a.name, a.phone, b.flights
FROM (SELECT DISTINCT id, event, name, phone from table1) as a
LEFT OUTER JOIN
(SELECT DISTINCT id, flights from table2) AS b ON a.ID = b.ID
Go to Top of Page
   

- Advertisement -