Connecting Tech Pros Worldwide Forums | Help | Site Map

Faster search

Newbie
 
Join Date: Feb 2008
Posts: 1
#1: Jan 5 '09
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 :
Expand|Select|Wrap|Line Numbers
  1. SELECT table_data.name, table_data.amount
  2. FROM table_data
  3. WHERE yr = 2009
But when I use the following subquery it is slower :
Expand|Select|Wrap|Line Numbers
  1. SELECT table_data.name, table_data.amount
  2. FROM table_data
  3. 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.

FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#2: Jan 5 '09

re: Faster search


Hello, Oreber.

Try to use join instead of subquery:
Expand|Select|Wrap|Line Numbers
  1. SELECT table_data.name, table_data.amount
  2. FROM table_data INNER JOIN parameter_table
  3.   ON table_data.yr=parameter_table.yr_today;
Just out of curiosity - what is this table combination supposed to do?

Regards,
Fish.
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,730
#3: Jan 6 '09

re: Faster search


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!
Reply