Question : SQL query help..to join or not to join

Hi,
   I am currently developing an application for a client, and the JavaDB SQL queries where working fine, until they gave me the data for their largest user, and it's around 30 times the size of the test data I had, and now all my SQL queries have gone extremely slow :(

  I have several tables, mainy accounts, product sales summary, products, product groups, product sub groups, etc. The application allows the user to drill down, so select an account, then select a Manufacturer, then select a product group and then it will display all matching products.

  Now, with my limited SQL, the query will end up looking something like this;

To display accounts (initially, with no drill down);
SELECT C.delaccount as account,C.practicename as name,c.address1,c.address2,c.address3,c.address4,c.postcode,sum(a.mon01) as value1,sum(a.mon13) as value2, 0,0,0,sum(a.year01) as year1, sum(a.year02) as year2,0,0 from app.customers C , APP.ANALSALEXREF A where c.delaccount=a.delaccount group by c.delaccount,c.practicename,c.address1,c.address2,c.address3,c.address4,c.postcode  ORDER BY value1 desc

To display accounts, with drill down criteria;
SELECT C.delaccount as account,C.practicename as name,c.address1,c.address2,c.address3,c.address4,c.postcode,sum(a.mon01) as value1,sum(a.mon13) as value2, 0,0,0,sum(a.year01) as year1, sum(a.year02) as year2,0,0 from app.customers C , APP.ANALSALEXREF A where c.delaccount=a.delaccount and manufacturer=270 and IMSMAIN = 61 group by c.delaccount,c.practicename,c.address1,c.address2,c.address3,c.address4,c.postcode  ORDER BY value1 desc

Now, this seems to work, but I'm not sure why I need thinks like 'where c.delaccount = a.delaccount', but without it, the query doesn't work.  I've read up on inner joins, outer joins, etc. but I'm basically getting fed up, and would appreciate some feedback on my queries.

Regards

Answer : SQL query help..to join or not to join

the queries look fine...
but the question is: do you have the proper indexes for the queries on the tables in place.
to "check", tell us which indexes (including primary keys) you have on the involved tables, and show the explain plan graph of the query (management studio => query => include actual explain plan  , then run the query, and see the additional tab generated ... )
Random Solutions  
 
programming4us programming4us