Re: Selecting data from one table based on conditions in another table



On Thu, 2 Feb 2006 11:50:40 -0800, "John Steen"
<moderndads(nospam)@hotmail.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
.



Relevant Pages

  • Re: Tricky Visual Basic Code help...
    ... moves the current record into a new record in table2. ... this with a little VBA code and a couple custom queries. ... Set a "pushFlag" column in the record in table1 to a specific ... If a duplicate is not found, ...
    (microsoft.public.access.formscoding)
  • Re: Help needed with importing XML
    ... You could add a gratuitous identity column to #temp and use ... Those examples showed how to decompose arbitrary XML in multiple ... table1 and table2. ... But there has to be something in the relational schema tying table1 ...
    (microsoft.public.sqlserver.xml)
  • Re: 2 column pulldown
    ... Allen Browne - Microsoft MVP. ... these field heading names come from Table2 since it is a lookup and so ... Table1 of course only has a single column name ... fieldX from Table1 is pulldown revealing candidate values of Table2. ...
    (microsoft.public.access.forms)
  • Re: Sliding and page breaks
    ... but I still have one nagging formatting problem. ... each entry in table1. ... simply pulls the first match in table2 instead of showing all the ... Otherwise I was thinking along the lines of your 2nd suggestion of using some calcs to consolidate the data down to a smaller number of tables used in the layout. ...
    (comp.databases.filemaker)
  • RE: Matching Type Query
    ... Table2 as the One side and Table 1 as the Many side? ... Do a Compact & Repair. ... compare every record in Table1 to each record in Table2 ...
    (microsoft.public.access.queries)