MULTEXT - Document MQL2. SgmlQL reference/Operators.
Select... from... where

The select/from/where is used to create a list of elements.

Prototype

list <-- select query
from v1 in list1
[, v2 in list2]*
[ where boolean ]

where query and boolean are expressions depending on v1, v2, ...

The value of such a query is a list L built as follows :

let L be the empty list, for each element v1 of list1 for each element v2 of list2... if the value of boolean is true then append the value of query to L

As classical with SQL the select_from_where is a nested join of lists list1, list2, ... followed by a restriction followed by a projection.

This operator can be obviously used with more than two lists.

Example a clause from with two variables:

Others practical examples:

Set the variable divs to contain the list of upper level divisions of $myfile:

global $divs =
  top DIV within file $myfile
;

Output the number of paragraphs in each upper level division of the document:

select
  count(every P within $d) . " "
from
  $d in $divs
;
3 6 4

Output the number of paragraphs in each sub-division of each upper level division of the document:

select
  count(every P within $d) . " "
from
  $d in
  (
    select
      top DIV within $s
    from
      $s in $divs
  )

;
3 3 3 2 2

Output number and date of each upper level division that contains a note:

select
  top {NUM, DATE} within $d
from
  $d in $divs
where
  not(empty(first NOTE within $d))
;
<NUM TYPE="wqref">
2579/91
</NUM><DATE>
14 November 1991
</DATE>

Output the number and date of each upper level division that contains a note, excluding the tags:

select
  text( (top {NUM, DATE} within $d), " -- " )
from
  $d in $divs
where
  not(empty(first NOTE within $d))
;
2579/91 -- 14 November 1991

Search for all upper level divisions that contain a paragraph matching a European country name; output the number of the question and the country code:

global $countries =
  top COUNTRY within file "countries.sgml"
;
select
  text(first NUM within $d) . "\t" .
  $c->CODE . "\n"
from
  $d in $divs,
  $c in $countries
where
  exists $p in (every P within $d):
    text($p) match text($c)
;
1463/91 DE
1463/91 UK
2579/91 DE
2579/91 NL

Note that the computation can be expansive for large lists since the entire cartesian product of list1, list2, etc. is computed.



| Top | Next | SgmlQL reference | LPL/CNRS | MULTEXT

Copyright © Centre National de la Recherche Scientifique, 1997.