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.
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 Description1Job2 Description2Job3 Description3Job4 Description4Job5 Description5Second table: NameJobA Relationship NameJobB-------- ------------ --------Job1 extension of Job2Job1 similar to Job3Job2 more interesting Job1Job5 harder Job4The result I wish to see is something like this: NameJobA JobDescription Relationship NameJobB JobDescription-------- -------------- ------------ -------- --------------Job1 Description1 extension of Job2 Description2Job1 Description1 similar to Job3 Description3Job2 Description2 more interesting Job1 Description1Job5 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, |
|
|
|
|
|