Optimize mysql Query

Hi All,
How can I make this query better?
Select a.* ,b.resourcetype from filedocuments a, documentcategories b where a.CategoryID = b.id and b.resourcetype = ? and a.ID=? and a.Version = ?;

Your answer to this is very much appreciate.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Some suggestions:

  - using "SELECT *" should be avoided unless you truly need all the fields in the table.
  - is a.ID supposed to be a unique?  If so, that's as fast as it will get.  
  - make sure you have indexes on a.CategoryID and b.resourcetype.  Depending on your data, you may want a multiple-column index on a.CategoryID and a.Version.
Can you run
in mysql terminal and post the result (you can scramble data, but dont damage numbers please)
that will make us wiser on indexes you need.
Show create table for each table

You are better off using join presumably a.categoryID points to b.description

The categories for this question is .. MySQL, access and Visual Basic?

The query seems like a prevompile, that then is reused with parameters being passed.

Presuming there are fewer rows in documentcategories versus the filedocuments

Select a.columns,b.resourcetype from documentcategories b inner join filedocuments a on b.id=a.CategoryID
where  b.id=? and b.resourcetype=?
PortletPaulEE Topic AdvisorCommented:
I (also) would assume a.ID is unique so this is all you need

    , b.resourcetype
FROM filedocuments a
      INNER JOIN documentcategories b ON a.CategoryID = b.id
WHERE a.ID = ?

You can include these conditions if you want to, but you make it more likely the query returns no rows at all

      AND a.Version = ?
      AND b.resourcetype = ?

these should be indexed:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RotebergAuthor Commented:
Thanks everyone for your comment I really appreciate it.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.