0

Im very new to SQL, thus excuse if this sounds stupid. I have two queries.

First

SELECT
  Tap_Back.*
FROM Tap_Back
WHERE Tap_Back.time > '2018-01-23'

Second

SELECT  
  readingdates.readdate  
FROM readingdates  
WHERE readingdates.readdate <= CURRENT_DATE()  
ORDER BY readingdates.readdate DESC  
LIMIT 1

Thus instead of hard coding the date in the First , I want to read it from a different table.

koryakinp
  • 3,989
  • 6
  • 26
  • 56
  • I would recommend to first learn Relational Algebra. Seems that what you want to do is a basic relational algebra operation (join). You can check this stackoverflow [question](https://stackoverflow.com/questions/17946221/sql-join-and-different-types-of-joins). – Daniel F. Jan 27 '18 at 03:16
  • Thanks for the link, I will definitely spend some time studying that. – Louis Van Der Walt Jan 27 '18 at 03:26

1 Answers1

0
SELECT Tap_Back.* 
FROM Tap_Back 
WHERE Tap_Back.time > (SELECT readingdates.readdate
  FROM readingdates
  WHERE readingdates.readdate <= CURRENT_DATE()
  ORDER BY readingdates.readdate DESC
  LIMIT 1)

or my preference would be

SELECT Tap_Back.* 
FROM Tap_Back 
WHERE Tap_Back.time > (SELECT min(readingdates.readdate)
  FROM readingdates
  WHERE readingdates.readdate <= CURRENT_DATE())
pgngp
  • 1,552
  • 5
  • 16
  • 26
Elroy Flynn
  • 3,032
  • 1
  • 24
  • 33