Faster search

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Oreber
    New Member
    • Feb 2008
    • 1

    Faster search

    HELP....

    I am trying to read a table that has 598,865 records. The problem is when I try to access it by year. When I use the following query it is fast :
    Code:
    SELECT table_data.name, table_data.amount
    FROM table_data
    WHERE yr = 2009
    But when I use the following subquery it is slower :
    Code:
    SELECT table_data.name, table_data.amount
    FROM table_data
    WHERE yr = (select yr_today from parameter_table)
    NOTE : parameter_table is a table with 1 record and 2 fields : yr_today(number , in this case 2009) and yr_prev(number, in this case 2008).

    Can anyone help me with the second query so it can be faster, because I don't like to hard code data in the queries.
    Last edited by NeoPa; Jan 6 '09, 01:45 PM. Reason: Please use the [CODE] tags provided
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Oreber.

    Try to use join instead of subquery:
    Code:
    SELECT table_data.name, table_data.amount
    FROM table_data INNER JOIN parameter_table
      ON table_data.yr=parameter_table.yr_today;
    Just out of curiosity - what is this table combination supposed to do?

    Regards,
    Fish.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      In general, Access "gives up" trying to be clever with SQL as soon as it hits a sub-query.

      Fish's INNER JOIN solution should sort you out though :)

      Welcome to Bytes!

      Comment

      Working...