Connecting Tech Pros Worldwide Forums | Help | Site Map

SQL Statement

Site Addict
 
Join Date: Mar 2007
Location: Oakland, California, USA
Posts: 522
#1: Nov 18 '07
I want a query that returns a list of keys and names.

I have 2 tables, a primary (tblP) and an alternate (tblA).

tblP
Key [AutoNumber]
Name Text
xxx Many Fields (interger & text)

tblA
Key [AutoNumber]
Ptr->P Long 'This is a pointer to Key in tblP
Name Text

Assume the following data:
tblP
Key Name
001 Smith
002 Joynes
003 OldBirdman

tblA
Key Ptr->P Name
01 002 Joins
02 001 Smythe

Desired result from Query WHERE Name LIKE ""*o*"" - Name in either tblP or tblA
Key Name
002 Joynes
002 Joins
003 OldBirdman

I know that one solution is to remove Name from tblP, add all the names to tblA, and therefore have a simple query "SELECT tblA.[Ptr->P], tblA.Name FROM tblA WHERE tblA.Name LIKE ""*o*""" . Is there a way with "OUTER JOIN" or some other SQL Phrase to do this? I have tried to simplify this problem, and in doing so the simple solution of moving all Names to tblA presents itself. In the actual application, this is not a viable solution.

OldBirdman

QVeen72's Avatar
Moderator
 
Join Date: Oct 2006
Location: Bangalore
Posts: 1,385
#2: Nov 18 '07

re: SQL Statement


Hi,

Try This :


Expand|Select|Wrap|Line Numbers
  1.  
  2. Select P.Key As NewKey, P.Name As NewName  From tblP P
  3. Where P.Name Like '*O*'
  4. Union All
  5. Select A.Ptr As NewKey , A.Name As NewName From tblA
  6. Where A.Name Like '*O*'
  7.  
  8.  
Regards
Veena
Site Addict
 
Join Date: Mar 2007
Location: Oakland, California, USA
Posts: 522
#3: Nov 19 '07

re: SQL Statement


I knew that there was an SQL keyword not accessable from Access Query Design. Thank you for both supplying the keyword and for the short, quick example.

Your example worked well within my application. Now I have to modify it to do exactly what I need done. Thanks again.

OldBirdman
Reply