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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need some help on sql

Status
Not open for further replies.

GaryC123

Programmer
Sep 10, 2002
1,041
NO
Table 1 contains ID and Area
Table 2 contains ID

ID is unique thru the 2 tables

I need to be able to say select from table 2 where Id matches the ID held in a session variable from table 1, but also pull all the records from table 2 where the area is the same as the matching ID's area. Does that make sense.



 
If your using MS SQL Server you might be able to use a UNION query. You should post your question in the database forum for your specific database.

-pete
I just can't seem to get back my IntelliSense
 
don't write in a big subquery, you can do like this
first,
query1= select [area] from tbl1 where ID='seesionID
then get the area=...(here we call someArea)
next,
query2 = select [id] from tbl1 where [area]='someArea'
then
Loop,fetch cursor, get some ID (aID)
during loop
query3 = select * from tbl2 where [ID] = 'aID'
end Loop

good luck
 
The original question is confusing...but this might be what you want...

SELECT * FROM table1
INNER JOIN table2 ON table1.ID = table2.ID
WHERE table1.Area = 'somevalue'

or

SELECT * FROM table2
WHERE table1.ID = table2.ID AND table1.Area = 'somevalue'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top