title: my SQL query runs slow need to optimise
body: <p>I'm having issues with the below query for my iPhone app. When the app runs the query it takes  quite a while to process the result, maybe around a second or so... I was wondering if the query can be optimised in anyway? I'm using the FMDB framework to proces all my SQL.</p>
  
  <pre><code>select pd.discounttypeid, pd.productdiscountid, pd.quantity, pd.value, p.name, p.price, pi.path 
  from productdeals as pd, product as p, productimages as pi 
  where pd.productid = 53252 
  and pd.discounttypeid == 8769 
  and pd.productdiscountid = p.parentproductid 
  and pd.productdiscountid = pi.productid 
  and pi.type = 362 
  order by pd.id 
  limit 1
  </code></pre>
  
  <p>My statements are below for the tables:</p>
  
  <pre><code>CREATE TABLE "ProductImages" (
      "ProductID" INTEGER,
      "Type" INTEGER,
      "Path" TEXT
  )
  
  CREATE TABLE "Product" (
      "ProductID" INTEGER PRIMARY KEY,
      "ParentProductID" INTEGER,
      "levelType" INTEGER,
      "SKU" TEXT,
      "Name" TEXT,
      "BrandID" INTEGER,
      "Option1" INTEGER,
      "Option2" INTEGER,
      "Option3" INTEGER,
      "Option4" INTEGER,
      "Option5" INTEGER,
      "Price" NUMERIC,
      "RRP" NUMERIC,
      "averageRating" INTEGER,
      "publishedDate" DateTime,
      "salesLastWeek" INTEGER
  )
  
  CREATE TABLE "ProductDeals" (
      "ID" INTEGER,
      "ProductID" INTEGER,
      "DiscountTypeID" INTEGER,
      "ProductDiscountID" INTEGER,
      "Quantity" INTEGER,
      "Value" INTEGER
  )
  </code></pre>