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)
 Help with join...

Author  Topic 

alexjamesbrown
Starting Member

48 Posts

Posted - 2009-01-29 : 19:34:09
Hi,
I have 2 tables.. one is called "Phone" and the other is called "Deal"

I basically need to get all Phones, where PhoneID appears in Deal..
There are around 1500 phones. Not all phones have a deal associated.
My minds gone blank.. i kno it's fairly straightforward...

Ive got this:

SELECT DISTINCT p.Name, p.Manufacturer, p.HandsetID, p.LaunchDate, p.Features, p.Description
FROM Phone AS p
RIGHT JOIN Deal
ON p.HandsetID = Deal.HandsetID

but it times out...??

without the DISTINCT... it returns 400x the amount it should...?
ARGH!!


any help, really appreciated!

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2009-01-29 : 20:06:17
quote:
Originally posted by alexjamesbrown

Hi,
I have 2 tables.. one is called "Phone" and the other is called "Deal"

I basically need to get all Phones, where PhoneID appears in Deal..
There are around 1500 phones. Not all phones have a deal associated.
My minds gone blank.. i kno it's fairly straightforward...

Ive got this:

Maybe:
SELECT DISTINCT p.Name, p.Manufacturer, p.HandsetID, p.LaunchDate, p.Features, p.Description
FROM Phone AS p
Inner JOIN Deal
ON p.HandsetID = Deal.HandsetID


but it times out...??

without the DISTINCT... it returns 400x the amount it should...?
ARGH!!


any help, really appreciated!


Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-29 : 23:29:59
try this also,
SELECT DISTINCT p.Name, p.Manufacturer, p.HandsetID, p.LaunchDate, p.Features, p.Description
FROM Phone AS p WHERE EXISTS (SELECT * FROM Deal WHERE p.HandsetID = HandsetID)

SELECT DISTINCT p.Name, p.Manufacturer, p.HandsetID, p.LaunchDate, p.Features, p.Description
FROM Phone AS p WHERE HandsetID IN (SELECT HandsetID FROM Deal )
Go to Top of Page
   

- Advertisement -