Take the 2-minute tour ×

I am using SQL Server

The data that I have is:


R_Time      ID   Q1
2012-02-26  14   8
2012-02-27  14   7
2012-02-27  15   8
2012-02-27  16   9
2012-02-27  11   10
2012-02-28  11   6
2012-02-28  14   10
2012-02-28  15   9



ID  Supervisor
11  2
14  2
15  3
16  3

What i am trying to due is only show R_Time and Q1 Entries from table1 where table2 Supervisor is 3

I know I will somehow have to do a join but im not quite sure how to.


share|improve this question
add comment

3 Answers

up vote 2 down vote accepted


You can use a inner join to get this done.

T-SQL INNER JOIN operator can be used in any FROM clause to combine records from two tables.


Select tbl1.R_Time, tbl1.Q1 from table1 tbl1
inner join table2 tbl2 on tbl2.Id = tbl1.Id
where tbl2.Supervisor = 3

More Information

share|improve this answer
add comment

hope it helps!

select t2.time 
from table1 t1 
 inner join table2 t2 
   on t1.Id = t2.Id
where t2.Supervisor = 3
share|improve this answer
add comment

Yup, you need to do an inner join:

    a.r_time, a.q1
    table1 a (nolock)
    inner join table2 b (nolock) on b.id = a.id
    b.supervisor = 3
share|improve this answer
why the use of nolock? that should only be used as a last resort and when your are sure that there will be no harm from dirty reads. In this case, not enough info was given to justify its use. If you just code like that in general, then that is a problem waiting to happen. Databases use locks for a reason, and bypassing them by default is never a good idea. not my "-1" btw. –  KM. Apr 26 '12 at 20:51
this is a programming habit i developed learning sql on databases with billion+ row tables and lots of writes. if your app uses no writes, fine, but as a general practice the benefits (better query performance) outweigh the costs (occasionally inconsistent state). –  Will Charczuk Apr 27 '12 at 19:16
occasionally inconsistent state, hope it wasn't a stock market or banking application! it does have the proper place, but it is certainly not something to teach someone that does not know what a join is. –  KM. Apr 27 '12 at 20:39
add comment

Your Answer


