I have an odd SELECT that I am having problems with...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Randell D.

    I have an odd SELECT that I am having problems with...


    Folks,

    Can I perform a single select query on two tables, where the results
    will include an optional value that might be in the second table?

    let me explain:
    I have two tables - address and department.

    The address table has a unique column to help identify the address (a
    hash key).

    The department table *could* have records, and if it does, it will have
    a hash corresponding to address.hash.

    Can I perform a SELECT to retrieve my address records from address table
    and include any optional records that some addresses might have in the
    department table?

    Do I have to perform two seperate selects for this, or is there a method
    for me to do this all in one query? My guess is two seperate selects...

    Help is appreciated - replies via the newsgroup to help others... thanks

    randell d.





  • Bill Karwin

    #2
    Re: I have an odd SELECT that I am having problems with...

    Randell D. wrote:[color=blue]
    > Can I perform a SELECT to retrieve my address records from address table
    > and include any optional records that some addresses might have in the
    > department table?[/color]

    A surprisingly high portion of tricky SQL query questions on this
    newsgroup can be solved with an outer join! :-)

    SELECT *
    FROM address AS a LEFT OUTER JOIN department AS d
    ON a.hash = d.hash;

    Regards,
    Bill K.

    Comment

    • Randell D.

      #3
      Re: I have an odd SELECT that I am having problems with...

      Bill Karwin wrote:[color=blue]
      > Randell D. wrote:
      >[color=green]
      >> Can I perform a SELECT to retrieve my address records from address
      >> table and include any optional records that some addresses might have
      >> in the department table?[/color]
      >
      >
      > A surprisingly high portion of tricky SQL query questions on this
      > newsgroup can be solved with an outer join! :-)
      >
      > SELECT *
      > FROM address AS a LEFT OUTER JOIN department AS d
      > ON a.hash = d.hash;
      >
      > Regards,
      > Bill K.[/color]

      I'm only just learning to understand JOINs... I appreciate the solution...

      Thanks
      Randell D.

      Comment

      Working...