Gyne
Gyne

Reputation: 45

Using subdate and max(date) in a subquery

I tried this query and got error. The sub query alone returns the desired result.

Select * 
from usi 
where present_date = select subdate(MAX(present_date), 1) AS PreviousDate from usi

What am I not doing correctly?

Upvotes: 1

Views: 383

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269445

You need parentheses around a subquery:

Select * 
from usi 
where present_date = (select subdate(MAX(present_date), 1) AS PreviousDate from usi);

As a note: subdate() -- while completely valid -- looks strange. I'm more used to seeing date_sub() or - interval 1 day.

Upvotes: 1

Related Questions