# Azure Data Lake Storage Gen1

### SELECT Statements <a href="#default" id="default"></a>

A SELECT statement can consist of the following basic clauses.

* SELECT
* INTO
* FROM
* JOIN
* WHERE
* GROUP BY
* HAVING
* UNION
* ORDER BY
* LIMIT

### SELECT Syntax

The following syntax diagram outlines the syntax supported by the SQL engine of the provider:<br>

\| <p>SELECT {</p><p>  \[ TOP \<numeric\_literal> | DISTINCT ]</p><p>  {</p><p>    *</p><p>    | {</p><p>        \<expression> \[ \[ AS ] \<column\_reference> ]</p><p>        | { \<table\_name> | \<correlation\_name> } .*</p><p>      } \[ , ... ]</p><p>  }</p><p>  \[ INTO csv:// \[ filename= ] \<file\_path> \[ ;delimiter=tab ] ]</p><p>  {</p><p>    FROM \<table\_reference> \[ \[ AS ] \<identifier> ]</p><p>  } \[ , ... ]</p><p>  \[ \[ </p><p>      INNER | { { LEFT | RIGHT | FULL } \[ OUTER ] }</p><p>    ] JOIN \<table\_reference> \[ ON \<search\_condition> ] \[ \[ AS ] \<identifier> ]</p><p>  ] \[ ... ]</p><p>  \[ WHERE \<search\_condition> ]</p><p>  \[ GROUP BY \<column\_reference> \[ , ... ]</p><p>  \[ HAVING \<search\_condition> ]</p><p>  \[ UNION \[ ALL ] \<select\_statement> ]</p><p>  \[</p><p>    ORDER BY</p><p>    \<column\_reference> \[ ASC | DESC ] \[ NULLS FIRST | NULLS LAST ]</p><p>  ]</p><p>  \[</p><p>    LIMIT \<expression></p><p>    \[</p><p>      { OFFSET | , }</p><p>      \<expression></p><p>    ]</p><p>  ]</p><p>}</p><p> </p><p>\<expression> ::=</p><p>  | \<column\_reference></p><p>  | @ \<parameter></p><p>  | ?</p><p>  | COUNT( \* | { \[ DISTINCT ] \<expression> } )</p><p>  | { AVG | MAX | MIN | SUM | COUNT } ( \<expression> )</p><p>  | NULLIF ( \<expression> , \<expression> )</p><p>  | COALESCE ( \<expression> , ... )</p><p>  | CASE \<expression></p><p>      WHEN { \<expression> | \<search\_condition> } THEN { \<expression> | NULL } \[ ... ]</p><p>    \[ ELSE { \<expression> | NULL } ]</p><p>    END</p><p>  | \<literal></p><p>  | \<sql\_function></p><p> </p><p>\<search\_condition> ::=</p><p>  {</p><p>    \<expression> { = | > | < | >= | <= | <> | != | LIKE | NOT LIKE | IN | NOT IN | IS NULL | IS NOT NULL | AND | OR | CONTAINS | BETWEEN } \[ \<expression> ]</p><p>  } \[ { AND | OR } ... ]</p> |
\| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

#### Examples

1. Return all columns:<br>

   | `SELECT * FROM Resources` |
   | ------------------------- |
2. Rename a column:<br>

   | `SELECT [Permission] AS MY_Permission FROM Resources` |
   | ----------------------------------------------------- |
3. Cast a column's data as a different data type:<br>

   | `SELECT CAST(AnnualRevenue AS VARCHAR) AS Str_AnnualRevenue FROM Resources` |
   | --------------------------------------------------------------------------- |
4. Search data:<br>

   | `SELECT * FROM Resources WHERE Type = 'FILE'` |
   | --------------------------------------------- |
5. Return the number of items matching the query criteria:<br>

   | `SELECT COUNT(*) AS MyCount FROM Resources` |
   | ------------------------------------------- |
6. Return the number of unique items matching the query criteria:<br>

   | `SELECT COUNT(DISTINCT Permission) FROM Resources` |
   | -------------------------------------------------- |
7. Return the unique items matching the query criteria:<br>

   | `SELECT DISTINCT Permission FROM Resources` |
   | ------------------------------------------- |
8. Summarize data:<br>

   | `SELECT Permission, MAX(AnnualRevenue) FROM Resources GROUP BY Permission` |
   | -------------------------------------------------------------------------- |

   See Aggregate Functions below for details.
9. Retrieve data from multiple tables.<br>

   | `SELECT Customers.ContactName, Orders.OrderDate FROM Customers, Orders WHERE Customers.CustomerId=Orders.CustomerId` |
   | -------------------------------------------------------------------------------------------------------------------- |

   See JOIN Queries below for details.
10. Sort a result set in ascending order:<br>

    | `SELECT FullPath, Permission FROM Resources  ORDER BY Permission ASC` |
    | --------------------------------------------------------------------- |
11. Restrict a result set to the specified number of rows:<br>

    | `SELECT FullPath, Permission FROM Resources LIMIT 10` |
    | ----------------------------------------------------- |
12. Parameterize a query to pass in inputs at execution time. This enables you to create prepared statements and mitigate SQL injection attacks.<br>

    | `SELECT * FROM Resources WHERE Type = @param` |
    | --------------------------------------------- |

### Aggregate Functions <a href="#default" id="default"></a>

#### COUNT <a href="#count" id="count"></a>

Returns the number of rows matching the query criteria.<br>

| `SELECT COUNT(*) FROM Resources WHERE Type = 'FILE'` |
| ---------------------------------------------------- |

#### COUNT(DISTINCT) <a href="#countdistinct" id="countdistinct"></a>

Returns the number of distinct, non-null field values matching the query criteria.<br>

| `SELECT COUNT(DISTINCT FullPath) AS DistinctValues FROM Resources WHERE Type = 'FILE'` |
| -------------------------------------------------------------------------------------- |

#### AVG <a href="#avg" id="avg"></a>

Returns the average of the column values.<br>

| `SELECT Permission, AVG(AnnualRevenue) FROM Resources WHERE Type = 'FILE'`  `GROUP BY Permission` |
| ------------------------------------------------------------------------------------------------- |

#### MIN <a href="#min" id="min"></a>

Returns the minimum column value.<br>

| `SELECT MIN(AnnualRevenue), Permission FROM Resources WHERE Type = 'FILE'` `GROUP BY Permission` |
| ------------------------------------------------------------------------------------------------ |

#### MAX <a href="#max" id="max"></a>

Returns the maximum column value.<br>

| `SELECT Permission, MAX(AnnualRevenue) FROM Resources WHERE Type = 'FILE'` `GROUP BY Permission` |
| ------------------------------------------------------------------------------------------------ |

#### SUM <a href="#sum" id="sum"></a>

Returns the total sum of the column values.<br>

| `SELECT SUM(AnnualRevenue) FROM Resources WHERE Type = 'FILE'` |
| -------------------------------------------------------------- |

### JOIN Queries <a href="#default" id="default"></a>

The Provider for Azure Data Lake Storage supports standard SQL joins like the following examples.

#### Inner Join

An inner join selects only rows from both tables that match the join condition:<br>

| `SELECT Customers.ContactName, Orders.OrderDate FROM Customers, Orders WHERE Customers.CustomerId=Orders.CustomerId` |
| -------------------------------------------------------------------------------------------------------------------- |

#### Left Join

A left join selects all rows in the FROM table and only matching rows in the JOIN table:<br>

| `SELECT Customers.ContactName, Orders.OrderDate FROM Customers LEFT OUTER JOIN Orders ON Customers.CustomerId=Orders.CustomerId` |
| -------------------------------------------------------------------------------------------------------------------------------- |

### Date Literal Functions <a href="#default" id="default"></a>

The following date literal functions can be used to filter date fields using relative intervals. Note that while the <, >, and = operators are supported for these functions, <= and >= are not.

#### L\_TODAY() <a href="#ltoday" id="ltoday"></a>

The current day.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_TODAY()` |
| ----------------------------------------------------- |

#### L\_YESTERDAY() <a href="#lyesterday" id="lyesterday"></a>

The previous day.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_YESTERDAY()` |
| --------------------------------------------------------- |

#### L\_TOMORROW() <a href="#ltomorrow" id="ltomorrow"></a>

The following day.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_TOMORROW()` |
| -------------------------------------------------------- |

#### L\_LAST\_WEEK() <a href="#llastweek" id="llastweek"></a>

Every day in the preceding week.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_LAST_WEEK()` |
| --------------------------------------------------------- |

#### L\_THIS\_WEEK() <a href="#lthisweek" id="lthisweek"></a>

Every day in the current week.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_THIS_WEEK()` |
| --------------------------------------------------------- |

#### L\_NEXT\_WEEK() <a href="#lnextweek" id="lnextweek"></a>

Every day in the following week.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_NEXT_WEEK()` |
| --------------------------------------------------------- |

Also available:

* L\_LAST/L\_THIS/L\_NEXT MONTH
* L\_LAST/L\_THIS/L\_NEXT QUARTER
* L\_LAST/L\_THIS/L\_NEXT YEAR

#### L\_LAST\_N\_DAYS(n) <a href="#llastndaysn" id="llastndaysn"></a>

The previous n days, excluding the current day.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_LAST_N_DAYS(3)` |
| ------------------------------------------------------------ |

#### L\_NEXT\_N\_DAYS(n) <a href="#lnextndaysn" id="lnextndaysn"></a>

The following n days, including the current day.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_NEXT_N_DAYS(3)` |
| ------------------------------------------------------------ |

Also available:

* L\_LAST/L\_NEXT\_90\_DAYS

#### L\_LAST\_N\_WEEKS(n) <a href="#llastnweeksn" id="llastnweeksn"></a>

Every day in every week, starting n weeks before current week, and ending in the previous week.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_LAST_N_WEEKS(3)` |
| ------------------------------------------------------------- |

#### L\_NEXT\_N\_WEEKS(n) <a href="#lnextnweeksn" id="lnextnweeksn"></a>

Every day in every week, starting the following week, and ending n weeks in the future.<br>

| `SELECT * FROM MyTable WHERE MyDateField = L_NEXT_N_WEEKS(3)` |
| ------------------------------------------------------------- |

Also available:

* L\_LAST/L\_NEXT\_N\_MONTHS(n)
* L\_LAST/L\_NEXT\_N\_QUARTERS(n)
* L\_LAST/L\_NEXT\_N\_YEARS(n)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appstrategy.com/apprules-r-documentation/platform/platform-features/system-settings/data-sources/sql-compliance/datawarehouse/adlsgen1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
