Jes Sie

Jes Sie

  • 700
  • 1.2k
  • 265k

Select Value From Table 1 That is NULL From Table 2

Dec 10 2019 1:46 AM
I have 2 tables.
 
Table1 contains 4 columns (Id, pt_RFID, sessionTime, sessionDate)
 
Table2 contains 7 columns (Id, pt_RFID, sessionTime, sessionDate, isTrainerShow, isTraineeShow)
 
Now, what I would like to achieve is to retrieve the sessionTime from Table1 where Table1.pt_RFID =@pt_RFID, Table2.sessionTime IS NULL and Table1.sessionDate = FORMAT (getdate(), 'yyyy-MM-dd').
 
The problem is, it did not give me the data that I wanted. Below is my actual Table:
 
Table1 
 
 
Table2

 
Below is my query that obviously is not correct:
  1. select   
  2.     st.sessionTime  
  3.     from dbo.tblPT_SessionTime st  
  4.     LEFT JOIN dbo.tblPT_Sessions sd ON sd.sessionTime = st.Id  
  5.       
  6.     WHERE sd.sessionTime IS NULL and st.pt_RFID = @pt_RFID AND st.sessionDate = FORMAT (getdate(), 'yyyy-MM-dd')  
Below is the result of the above query and should give me 15 rows since the sessionDate of the 1st row from Table2 is not the current date.
 
I hope someone could assist me. 

Answers (4)