Skip to content
Andrey Gershun edited this page May 27, 2015 · 9 revisions

FROM

Syntax:

    SELECT ... FROM (table1|from-function|json-object|parameter), table2...
    SEARCH selectors FROM (table|json-objects|from-function|parameter)

From database table

    alasql('SELECT * FROM albums');
    alasql('SELECT * FROM mydb.test');

From parameter

    alasql(‘SELECT * FROM ?,[singers]);

From array parameter

    alasql(‘SELECT * FROM [?],[singers]);

From file (FROM-function)

    alasql('SELECT * FROM XLSX(“medals.xlsx”)');

From stdin (for Node.js)

    alasql('SELECT * FROM TXT()');

From SELECT statement

    alasql('SELECT * FROM (SELECT * FROM  (SELECT * FROM City))');

From functions

  • TXT()
  • JSON()
  • CSV()
  • TSV() / TAB()
  • XLSX() / XLS()
  • HTML()

From parameters (? and [?])

  • ? – just value
  • [?] – converts array to array of arrays
    [1,2,3] => [[1],[2],[3]]

Array of objects

     alasql(‘SELECT city.population FROM ? AS city’,[city]);

Array of arrays

     alasql(‘SELECT [0]+[1]*[2] FROM ?’, [data]);

Object

     alasql(“SELECT [1] FROM ? WHERE [0] = ‘one’”,[{one:1,two:2}])

String

    alasql(“SELECT LEN([0]) FROM ?,[“Multi \n line \n text”])

Parameter data type conversion

String => array of lines

    alasql('SELECT * FROM ? WHERE LEN([0]) > 10',[“abc\ncde”])
    => [[“abc”],[“cde”]]

Objects => array of pairs key-value

    {a:1,b:2} => [[“a”,1],[“b”,2]]

Table Alias

FROM table alias

    alasql('SELECT * FROM ? City');
    alasql('SELECT * FROM album AS a');

Examples:

    alasql('SELECT * FROM cities');
    var data = [{city:"Boston"}, {city:"Los Angeles"}];
    alasql('SELECT * FROM ? ORDER BY city',[data]);

You can also get data from stdin stream (for Node.js only). For example, how to calculate number of lines in incoming text file:

    alasql('SELECT COUNT(*) FROM TXT()');

See also: SELECT, SEARCH

Clone this wiki locally