extracts data from a table in an SQL connection.


extracts data from particular columns.


only extracts data that matches cond.


  • To use SQLSelect, you first need to load DatabaseLink using Needs["DatabaseLink`"].
  • The following options can be given:
  • "Distinct"Falsewhether to return only distinct results
    "FetchSize"AutomaticJDBC driver hint for filling result sets
    "GetAsStrings"Falsewhether to return the results as strings
    "MaxFieldSize"Automaticbyte limit for variable-length column types
    "MaxRows"Automaticthe maximum number of rows to return
    "ShowColumnHeadings"Falsewhether to return headings with the results
    "SortingColumns"Nonehow to sort the data
    "ColumnSymbols"Nonesymbols to be associated with results
    "Timeout"$SQLTimeoutthe timeout for the query


open allclose all

Basic Examples  (1)

If you find that the examples in this section do not work as shown, you may need to install or restore the example database with the DatabaseLink`DatabaseExamples` package, as described in Using the Example Databases.

Open a connection:

Select all data from a table:

Select only certain columns:

Join data from multiple tables:

Select data matching a condition:

Select data matching a pattern:

Select data matching a list:

Scope  (1)

Select data matching a condition:

Combine conditions using And and Or:

Options  (8)

"Distinct"  (1)

Retrieve unique values:

"FetchSize"  (1)

The "FetchSize" option suggests to the JDBC driver a number of rows to fetch on each visit to the database. Increasing this parameter reduces the amount of network traffic required to execute a query, at the cost of memory used:

Compute memory in use, including both kernel and Java layers:

Fetch a large result with a small fetch size:


Fetch a large result with a large fetch size:

"GetAsStrings"  (1)

Retrieve data without converting it to Wolfram Language types:

"MaxFieldSize"  (1)

For some variable-length column types the "MaxFieldSize" option can be used to limit the number of bytes returned for a field:

Create a table with a VARCHAR field:

Insert string data:

Select string contents, limiting byte length of results:

"MaxRows"  (1)

Limit the number of rows returned in a result:

"ShowColumnHeadings"  (1)

Include column names as the first row of the results:

"SortingColumns"  (1)

Specify columns to order by:

"ColumnSymbols"  (1)

Supply a list of symbols for query results to be assigned to:

Create symbols automatically:

Supply a function to operate on column names and results. If column headings have not been requested, the first argument to the function will be Null:

Applications  (1)