How can I "ORDER BY" using SQLSelect?

1

A pretty straightforward problem, you would think, but I cannot seem to find the answer in the documentation for SQLSelect.

The query I want to run is the following:

SELECT id, measurement, timestamp FROM myTable WHERE id IN (1, 2) ORDER BY timestamp

The Mathematica query I have so far is:

SQLSelect[dbConn,
    "myTable",
    {"id", "measurement", "timeStamp"},
    SQLMemberQ[{1, 2}, SQLColumn["id"]]
]

But I cannot seem to find an option to insert the ORDER BY requirement.

Shredderroy

Posted 2014-09-10T18:14:52.670

Reputation: 3 879

Answers

4

You can use "SortingColumns" in SQLSelect or simply use the SQL statement inside SQLExecute.

In the second case you simply write the SQL statement in the string:

SQLExecute[dbConn, "SELECT id, measurement, timestamp FROM myTable WHERE id IN (1, 2) ORDER BY timestamp"]

And you are returned triplets with {id, measurement, timestamp}.

mgm

Posted 2014-09-10T18:14:52.670

Reputation: 969