UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Help With Syntax On Simplye Subquery In 2008 T-sql, Office 2010    
 
   
bakersburg9
post May 20 2012, 10:05 PM
Post #1

UtterAccess Ruler
Posts: 4,237
From: Downey, CA



I have to look up employees one at a time from our employee table - then I have to look up (query) that employee's supervisor - the unique identifier for the first query is EmpID - and when the query returns the record for that employee, it shows the SupID (The employee's supervisor's EmpID) - so I have to make a note of the employee's supervisor's employee ID, then run a query using the original employee's supervisor's employee ID as the criteria.

Is there a way to have the record from tblEmployee for the employee I'm querying on, and include in the record set that employee's supervisor as well ?

I would think there would be, but I can't get the syntax right

Any help would be greatly appreciated.

Steve
Go to the top of the page
 
+
Peter46
post May 21 2012, 04:45 AM
Post #2

UtterAccess VIP
Posts: 7,394
From: Oadby Leics, UK



I''m not sure if you are saying you want to do this for one specifc employee or for all employees.
For all employees do...


Select E.*, S.*
from Employeetable as E inner join Employeetable as S
on E.SupId = S.EmpId

For a single employee add a where clause..

Where E.empid = 123

or whatever the value is.
Go to the top of the page
 
+
bakersburg9
post May 21 2012, 10:00 AM
Post #3

UtterAccess Ruler
Posts: 4,237
From: Downey, CA



QUOTE (Peter46 @ May 21 2012, 09:45 AM) *
I''m not sure if you are saying you want to do this for one specifc employee or for all employees. or all employees do...

Select E.*, S.*
from Employeetable as E inner join Employeetable as S
on E.SupId = S.EmpId

For a single employee add a where clause.. Where E.empid = 123


Peter - that did not work - to test it, I used my own employee ID - what returned was just one record - the info on me, but I wanted to see 2 records - me and my supervisor - just for grins I tried Left join right join, full outer join, nothing - every time I just got one record - my record.
Go to the top of the page
 
+
Peter46
post May 21 2012, 10:52 AM
Post #4

UtterAccess VIP
Posts: 7,394
From: Oadby Leics, UK



I suggest you scroll to the right a bit when you look at your result.
Go to the top of the page
 
+
bakersburg9
post May 21 2012, 11:17 AM
Post #5

UtterAccess Ruler
Posts: 4,237
From: Downey, CA



QUOTE (Peter46 @ May 21 2012, 03:52 PM) *
I suggest you scroll to the right a bit when you look at your result.

Oops - sorry - I wanted it as two separate records, like a subquery - is that possible ?
Go to the top of the page
 
+
Peter46
post May 21 2012, 11:41 AM
Post #6

UtterAccess VIP
Posts: 7,394
From: Oadby Leics, UK



You can try this, ( but I'm just making it up (:-) )



Select * from Employeetable where EmpId = [Enter EmpID]
Union All
Select * from Employeetable where empid = Dlookup("supId", "employeetable", "Empid= " & [Enter EmpID]

Edit:
Sorry - I forgot you are asking about T_Sql, not Access sql. I don't know what the equivalent to this would be in T_SQL.
Go to the top of the page
 
+
bakersburg9
post May 21 2012, 11:52 AM
Post #7

UtterAccess Ruler
Posts: 4,237
From: Downey, CA



QUOTE (Peter46 @ May 21 2012, 04:41 PM) *
You can try this, ( but I'm just making it up (:-) )

Select * from Employeetable where EmpId = [Enter EmpID]
Union All
Select * from Employeetable where empid = Dlookup("supId", "employeetable", "Empid= " & [Enter EmpID]

Edit:
Sorry - I forgot you are asking about T_Sql, not Access sql. I don't know what the equivalent to this would be in T_SQL.


That's ok - thanks for your help - I was more trying to learn subqueries - thanks !
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 22nd May 2013 - 01:37 PM