Product SiteDocumentation Site

10.3. Where Clauses

Where clauses are used for filtering.
For each incoming tuple, the expression in the where clause is evaluated to a boolean (possibly converting an atomic to a boolean). If this boolean is true, the tuple is forwarded to the next clause, otherwise it is dropped.
The following query corresponds to "SELECT q.title as question, q.question_id as id FROM faq WHERE CONTAINS(question, 'NoSQL')".
Example 10.8. A where clause.
for $question in collection("faqs")
where contains($question.title, "NoSQL")
return {
  "question" : $question.title,
  "id" : $question.question_id
}
Results:
{
  "question" : "MySQL and NoSQL: Help me to choose the righ
t one",
  "id" : 4419499
}
{
  "question" : "Full-text search in NoSQL databases",
  "id" : 5453872
}

JSONiq can do joins with where clauses, too:
Example 10.9. A join with a where clause.
for $question in collection("faqs"),
    $answer in collection("answers")
where $question.question_id eq $answer.question_id
return {
  "question" : $question.title,
  "answer score" : $answer.score
}
Results:
{
  "question" : "MySQL and NoSQL: Help me to choose the righ
t one",
  "answer score" : 17
}
{
  "question" : "MySQL and NoSQL: Help me to choose the righ
t one",
  "answer score" : 1
}
{
  "question" : "Redis, CouchDB or Cassandra?",
  "answer score" : 34
}
{
  "question" : "Full-text search in NoSQL databases",
  "answer score" : 6
}
{
  "question" : "Find CouchDB docs missing an arbitrary fiel
d",
  "answer score" : 0
}
{
  "question" : "Find CouchDB docs missing an arbitrary fiel
d",
  "answer score" : 1
}