|
Home > Archive > MS SQL Server MSEQ > February 2006 > Selecting data from one table based on conditions in another table
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Selecting data from one table based on conditions in another table
|
|
| John Steen 2006-02-02, 8:24 pm |
| I'm used to doing simple queries from individual tables, so I hope someone
can help with this.
I need to select unique data from a column in table1 based on the value of a
column in table2. The data in the column of table1 is not all unique, so I
also need to filter out extra occurrances of of the data. So if the name
JOHN SMITH appears 27 time in the column in table 1, I only want to return
one instance of the name.
Thanks in advance.
--
John Steen
remove (nospam) from e-mail address to send me a message
| |
| Hugo Kornelis 2006-02-02, 8:24 pm |
| On Thu, 2 Feb 2006 11:50:40 -0800, "John Steen"
< moderndads(nospam)@h
otmail.com> wrote:
>I'm used to doing simple queries from individual tables, so I hope someone
>can help with this.
>
>I need to select unique data from a column in table1 based on the value of a
>column in table2. The data in the column of table1 is not all unique, so I
>also need to filter out extra occurrances of of the data. So if the name
>JOHN SMITH appears 27 time in the column in table 1, I only want to return
>one instance of the name.
>
>Thanks in advance.
Hi John,
Based on your very vague narrative, here's a shot in the dark:
SELECT DISTINCT Table1.SomeColumn
FROM Table1
INNER JOIN Table2
ON Table2.LinkingColumn = Table1.LinkingColumn
WHERE Table2.OtherColumn = @WhateverYouLookFor
If this is not what you want, then please post better specification. A
good explanation of what you need to post and how you can assemble it is
to be found at www.aspfaq.com/5006.
--
Hugo Kornelis, SQL Server MVP
|
|
|
|
|