Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement

Status
Not open for further replies.

Leon1977

IS-IT--Management
Jun 27, 2001
79
BG
hi I need help with an select statement
I have two table Stores and sells
so in the Stores table i have store_id and store_name
and in sells i have from_store_id and to_store_id
Both from_store_id and to_store_id refer store_id from stores. I need a single select statement which will bring out the store_names for both from and to stores
 
You simply need to do two joins - that is treat it like you have two STORES tables - one for "from" and one for "two":

SELECT to.store_name, from.store_name
FROM sells, stores to, stores from
WHERE to.store_id = sells.to_store_id
AND from.store_id = sells.from_store_id
AND and other selection criteria you want
 
select f.store_name from_name,
t.store_name to_name
--,<columns from sells>
from Stores f, sells s, stores t
where s.from_store_id = f.store_id
and s.to_store_id = t.store_id

 
select froms.store_name as from_store,
tos.store_name as to_store
from stores froms,
stores tos,
sells int
where froms.store_id = int.from_store_id
and int.to_store_id = tos.store_id
 
It looks like we three are writing response at the sime time - funny...
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top