Uploaded image for project: 'Couchbase Documentation'
  1. Couchbase Documentation
  2. DOC-269

Inaccurate SQL query?

    XMLWordPrintable

Details

    Description

      In the last example of the "Translating SQL WHERE to map/reduce", I think that equivalent SQL for the following query should be different:

      ?startkey=["carrot","rice",0]&key=["carrot","rice",20]

      Original query:

      SELECT recipeid FROM recipe JOIN ingredients on ingredients.recipeid = recipe.recipeid
      WHERE (ingredient = 'carrot' OR ingredient = 'rice') AND totaltime = 20

      This query is inaccurate because it returns the recipes which have at least one of the ingredient and its total time is exactly 20 minutes.

      My suggested query:

      SELECT recipeid FROM recipe
      JOIN ingredients i1 ON ingredients.recipeid = recipe.recipeid
      JOIN ingredients i2 ON ingredients.recipeid = recipe.recipeid
      WHERE (i1.ingredient IN ('carrot',rice')) AND
      (i2.ingredient IN ('carrot',rice')) AND
      (totaltime < 20 AND totaltime > 0)

      Cheers

      Reporter: Eyal
      E-mail: mush.eyal@gmail.com

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            marija Marija Jovanovic (Inactive)
            docsite-collector Docs Site Collector
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes

                PagerDuty