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

SQL Query Help 1

Status
Not open for further replies.

megmogg

Programmer
Jul 14, 2005
76
GB

Hi All

Need some help with a query.

I have two tables related to each other as header and detail. Both have a userid.

Code:
[b]Table1[/b]
[u]keyid1[/u]
overview
userid

Code:
[b]Table1[/b]
[u]keyid2[/u]
keyid1 *
overview
userid

My form I have developed has two grids, the top shows table1 and the second shows related in table2.

However, one of the filters on the form needs to show the related users. But the issue is the related users can be in header and/or detail, so I need to show header records that have detail records with the user assigned but that user may not be assigned to the header.

Any help appreciated.





 
Can you clarify what you are looking for..
show an exmple of your output.

Dr.Sql
Good Luck.
 

Thanks for the reply.


table1 contains

Code:
keyid1  Overview          userid
2       "Call Customer"   3

table2 contains:

Code:
keyid2  keyid1 Overview          userid
5       2      "Call Customer"   6


basically, my application has two queries to retrieve the data, what I want it to retrive data from table 1 if userid is 6 OR has a related table2 entry with a userid of 6.





 
Code:
select tb1.keyid1 from table1 tb1
inner join table2 tb2 on tb1.keyid1 = tb2.keyid1
where tb1.userid = 6 or tb2.userid = 6


"I'm living so far beyond my income that we may almost be said to be living apart
 

Thanks for the reply.

That brings back additional rows, but I sorted that out with the distinct clause.

dont know what was wrong with me, was trying to complicate it too much with a sub query and exists.

Thanks


 
dont worry i do that all the time - cant see the wood for the trees!

"I'm living so far beyond my income that we may almost be said to be living apart
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top