View previous topic :: View next topic
|
Author |
Message |
naveensri2005 Currently Banned New User
Joined: 22 Mar 2005 Posts: 51 Location: chennai
|
|
|
|
hi
I have one table is there . that table contain 2000 reacords are there. in that table contain date fields is there? but i want to retrive only last five days records only how to write the query?
naveens |
|
Back to top |
|
|
MGIndaco
Active User
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
|
|
|
|
I've some problem in understanding your post but i think that you can subtract from current date all the day you need as you can see below:
Code: |
SELECT * FROM MYDB.MYTB
WHERE DATE = CURRENT_DATE - 5 DAYS |
|
|
Back to top |
|
|
priyesh.agrawal
Senior Member
Joined: 28 Mar 2005 Posts: 1448 Location: Chicago, IL
|
|
|
|
Is this code going to extract records only for last fifth day from today.
Quote: |
I've some problem in understanding your post |
I think naveensri2005 asked all the recs for the all last five days.
so it could have been.
Code: |
SELECT * FROM MYDB.MYTB
WHERE DATE IN (
CURRENT_DATE,
CURRENT_DATE - 1 DAYS.
CURRENT_DATE - 2 DAYS.
CURRENT_DATE - 3 DAYS.
CURRENT_DATE - 4 DAYS.
); |
Regards,
Priyesh. |
|
Back to top |
|
|
MGIndaco
Active User
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
|
|
|
|
Or you can also specify:
Code: |
SELECT * FROM MYDB.MYTB
WHERE DATE >= CURRENT_DATE - 5 DAYS |
It's another way to do the same request... |
|
Back to top |
|
|
ajay_dheepak
New User
Joined: 12 May 2005 Posts: 32 Location: Chennai
|
|
|
|
SELECT * FROM MYDB.MYTB
WHERE DATE >= CURRENT DATE - 4 DAYS
AND DATE <= CURRENT DATE; |
|
Back to top |
|
|
MGIndaco
Active User
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
|
|
|
|
OPS... |
|
Back to top |
|
|
MGIndaco
Active User
Joined: 10 Mar 2005 Posts: 432 Location: Milan, Italy
|
|
|
|
Code: |
SELECT * FROM MYDB.MYTB
WHERE DATE BETWEEN CURRENT_DATE - 4 DAYS AND CURRENT_DATE |
This is better... |
|
Back to top |
|
|
|