Re: [Q] SQL question
Posted in 1995
>>Is there a way for me to get a select statement to bring fields from two
>>tables by a common select criteria?
>
>>e.g
>>Select lname, fname, status
>>from contractors, visitors
>>where status ="IN">
>>I know this does not work. It gives me a cartesian product. I have been
>>exploring different methods but I don't get the required result. The two
>>tables have the same for the columns, and the criteria, which is STATUS
>>="IN" is common to both. I just want to combine the info from the two
>>tables so that I can report it.
>
With respect to M. Goddard, his solution assumes that you want the tables
combined. M. Goddard's will give you all the records from both tables where
the status is "IN" and the names are the same.
Another option is:
Select lname, fname, status
from contractors
where status ="IN"
UNION ALL
Select lname, fname, status
from visitors
where status ="IN"
This will give you all the records from both tables where the status is "IN".
Depending on your needs, you might want to add a literal to the request so
that you can tell which table the record came from --
Select "Contractor", lname, fname, status
from contractors
where status ="IN"
UNION ALL
Select "Vistor", lname, fname, status
from visitors
where status ="IN"
John Callaway
Bath Iron Works
The humble opinions stated above are my own. Use at your own risk.