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 2000 Forums
 SQL Server Development (2000)
 Combined Selections?

Author  Topic 

kaleidoscope
Starting Member

5 Posts

Posted - 2009-01-20 : 17:19:58
Hi Everyone,
A question from a newbie:
I would like to join 2 tables in what seems to be a combined SELECT statements, but nothing seems to work.

The following is an example of what I'd like to accomplish (The actual tables are really huge: Millions of entries, so any optimization is greatly appreciated). Spent long hours in vain... frustrating.

First table:

NameJob JobDescription
------ --------------
Job1 Description1
Job2 Description2
Job3 Description3
Job4 Description4
Job5 Description5

Second table:
NameJobA Relationship NameJobB
-------- ------------ --------
Job1 extension of Job2
Job1 similar to Job3
Job2 more interesting Job1
Job5 harder Job4

The result I wish to see is something like this:

NameJobA JobDescription Relationship NameJobB JobDescription
-------- -------------- ------------ -------- --------------
Job1 Description1 extension of Job2 Description2
Job1 Description1 similar to Job3 Description3
Job2 Description2 more interesting Job1 Description1
Job5 Description5 harder Job4 Description4

Any idea!?
Thanks


kaleidoscope
Starting Member

5 Posts

Posted - 2009-01-20 : 18:08:29
Found it!

The trick was to use SELECT DISTINCT :

SELECT DISTINCT NameJobA, (SELECT JobDescription FROM JOBDESCRIPTION WHERE NameJobA = NameJob) AS JDA, RELATIONSHIP, NameJobB, (SELECT JobDescription FROM JOBDESCRIPTION WHERE NameJobB = NameJob) AS JDB
FROM OVERLAP, JOBDESCRIPTION;

Cheers,
Go to Top of Page
   

- Advertisement -