Question : Help with subquery

Database Server : Interbase 6

I have a table that contains a fair amount of data (93000+ Rows). The data goes back to Jan 1, 2000.

I need to pull a query - at this point one time only - for any new company from Sept 13 2002 to current date.

The table layout is like this:

"License number", (PKEY)
"Activity Date",
Many Fields,
"Licensee"
Some more fields.

The basic idea is that company x, if new, will only have activity posted on dates that are greater than Sept 13. Older companies may or may not have entries with entry dates greater than Sept 13.

So, what I've come up with is

SELECT DISTINCT("Licensee") FROM "Activity"
WHERE "Licensee" NOT IN
  ( SELECT DISTINCT("Licensee") FROM "Activity"
    WHERE "Activity Date" >= '2002-09-13' )

Which should return the results that I am looking for. However, this query is running a *very* long time, and I'm hoping that there is something that I can do to speed it up.

I had also played with

SELECT "Licensee",MIN("Activity Date") FROM "Activity"
GROUP BY "Licensee"

However, I could not find a way to filter it based on "Activity Date"

Answer : Help with subquery

You are on right track:

SELECT "Licensee",MIN("Activity Date") FROM "Activity"
GROUP BY "Licensee"
HAVING MIN("Activity Date") >= '2002-09-13'

Also Asc index on Activity Date will help to speedup


Bojidar Alexandrov
Random Solutions  
 
programming4us programming4us