[Solved] Base Query to previous date

Discuss the database features
Post Reply
emre
Posts: 2
Joined: Wed May 02, 2018 4:23 pm

[Solved] Base Query to previous date

Post by emre »

Hi Everyone,
I'am quite new in this forum and trying to create a basic form. In my case, I need to query -1 day on the table 2 by refering to table 1 where ID=0. Is it possible using something like following. I am sorry for my poor explanation If I do not use right terms.

SELECT "ID", "Date" FROM "Table1" WHERE "Date" = ( SELECT "Date" FROM "Table2" WHERE "ID" = 0 ) -1

thank you
Last edited by robleyd on Thu May 03, 2018 1:38 am, edited 1 time in total.
Reason: Tagged [Solved] [robleyd, Moderator]
Open Office 4.1.5 - Windows_10
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Base Query to previous date

Post by Villeroy »

If you happen to use the embedded HSQL which is documented here: http://www.hsqldb.org/doc/1.8/guide/ch09.html

Code: Select all

SELECT "T1".* 
FROM "T1","T2" 
WHERE "T2"."ID"=0
  AND DATEDIFF('day', "T1"."Date", "T2"."Date") = -1 
DATEDIFF returns an integer. Note that HSQL 1.8 is missing a DATEADD function. In HSQL 2 DATEADD('day', 13, "Date") returns the dates 13 days ahead of the "Date" field.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
emre
Posts: 2
Joined: Wed May 02, 2018 4:23 pm

Re: Base Query to previous date

Post by emre »

That resolved my problem. Thank you for your help.
Open Office 4.1.5 - Windows_10
Post Reply