View previous topic :: View next topic
|
Author |
Message |
karthikbabudh
New User
Joined: 08 Sep 2003 Posts: 32 Location: Toronto <-> Bangalore
|
|
|
|
Hi,
I have table like this.
Field1 Date Added
=============
REP01 30-11-2007
REP02 01-12-2007
REP03 02-12-2007
REP04 03-12-2007
REP01 04-12-2007
REP05 04-12-2007
I want to fetch only the records which are added today and which already does not exists. So the output I' am expecting from above table is
"REP05 04-12-2007". Is it possible using simple SQL?
Thanks,
Karthik. |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
karthikbabudh wrote: |
which already does not exists |
You need to explain that a little better. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
and why do you NOT want REP01 04-12-2007? |
|
Back to top |
|
|
karthikbabudh
New User
Joined: 08 Sep 2003 Posts: 32 Location: Toronto <-> Bangalore
|
|
|
|
Dick,
I want all the "Field1" values which are added today but is not available for any of the existing dates. In my table, 2 records are added today.
REP01 04-12-2007
REP05 04-12-2007
Out of the above 2 records, REP01 is already available for the date "30-11-2007" (1st record in table). So I want only REP05. Hope I answered your question.
Thanks,
Karthik. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
why not use a query in the style of
Code: |
select what_you_need from Your_table
were date = todays_date and
date not in ( select date from Your_table were date less_then todays_date )
|
|
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Code: |
SELECT FIELD1 FROM TABLE A
WHERE DATE_ADDED = CURRENT DATE
AND NOT EXISTS (SELECT 1 FROM TABLE B
WHERE A.FIELD1 = B.FIELD1
AND B.DATE_ADDED < A.DATE_ADDED)
|
|
|
Back to top |
|
|
karthikbabudh
New User
Joined: 08 Sep 2003 Posts: 32 Location: Toronto <-> Bangalore
|
|
|
|
I got it. Thanks Craq and Enrico
Karthik. |
|
Back to top |
|
|
|