I am new to SQL. I have a table which contains information about ads. Which function should I use, to find id of all ads posted within the past three days?
Asked
Active
Viewed 60 times
1
-
What [RDBMS](http://en.wikipedia.org/wiki/Relational_database_management_system) you are using? `SQL Server`? `MySQL`? `Oracle`? `DB2`? etc.. – John Woo Feb 09 '13 at 07:20
-
Also, post the table structure. – Orangecrush Feb 09 '13 at 07:21
-
@JW, Oracle. it contains pdate which has date as domain, and some other information – Marshall Black Feb 09 '13 at 07:25
2 Answers
1
Select ID --the id field
From tblAds --the ads table
WHERE Ad_Date >= DATEADD(day,-3,getDate()) --the filter. I am assuming Ad-Date is the name of the ad's date field
order by Ad_Date ASC -- order it

Captain Kenpachi
- 6,960
- 7
- 47
- 68
1
For Oracle DB, use this,
SELECT id
FROM tablename
WHERE TRUNC(pdate) >= TRUNC(SYSDATE) - 3;

Orangecrush
- 1,970
- 2
- 15
- 26
-
Thanks, it works. Can you please explain, what does "DUAL" do here? – Marshall Black Feb 09 '13 at 07:37
-
1@MarshallBlack Info on [DUAL](http://stackoverflow.com/questions/73751/what-is-the-dual-table-in-oracle) – Orangecrush Feb 09 '13 at 07:40
-
yeap, I was gonna do that, just was reading the article about dual – Marshall Black Feb 09 '13 at 07:44