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)
 Need help with this query...See inside

Author  Topic 

Sanatan
Starting Member

19 Posts

Posted - 2009-03-12 : 07:24:56
I have two tables with the following design. I need to fetch some data as stated below. Please assist with the query design.

Table 1
Col_1 Col_2
Sh1 Map1
Sh1 Map2
Sh1 Map3
Sh2 Map1
Sh3 Map3

Table 2
Col_1 Col_2
Map1 Owner1
Map2 Owner1
Map2 Owner2
Map3 Owner1
Map3 Owner3

The data displayed for Owner1 should be as below.
Owner1
------
Sh1
Sh2
Sh3

Owner2
------ _
Sh1

Owner3
-----
Sh3


Basically I want to retrieve all Col_1 values for a given Owner based on their login. I can capture the login and determine the owner. How do I join the Table1 and Table2 to retrieve the appropriate Col_1 values as listed above. Please help.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-12 : 07:28:36
[code]SELECT DISTINCT t1.Col_1 AS [Owner]
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t2.Col_1 = t1.Col_2
WHERE t2.Col_2 = 'Owner1'
ORDER BY t1.Col_1[/code]


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

Sanatan
Starting Member

19 Posts

Posted - 2009-03-12 : 08:59:00
Thanks Peso, I appreciate your quick help!

quote:
Originally posted by Peso

SELECT DISTINCT	t1.Col_1 AS [Owner]
FROM Table1 AS t1
INNER JOIN Table2 AS t2 ON t2.Col_1 = t1.Col_2
WHERE t2.Col_2 = 'Owner1'
ORDER BY t1.Col_1



E 12°55'05.63"
N 56°04'39.26"


Go to Top of Page
   

- Advertisement -