Contents7 sections ↓
SuiteQL is NetSuite's SQL-based query language for reading NetSuite data with joins, subqueries, UNION and GROUP BY. Use it when a saved search can't express the question, or when code needs the data: it runs in SuiteScript's N/query module, through REST web services and through SuiteAnalytics Connect, with the same role-based access as SuiteAnalytics Workbook. Keep saved searches for reports that business users maintain.
Last reviewed: 25 October 2026, against Oracle's NetSuite 2026.2 documentation and release notes.
SuiteQL for NetSuite: what it is and why it matters
SuiteQL is NetSuite's query language, based on the SQL-92 revision, and it lets you query NetSuite data with familiar SQL syntax. Per Oracle's SuiteQL overview, it accepts SQL-92 and Oracle SQL syntax, but you can't use both in the same query. If you've hit the edges of saved searches — joins the interface doesn't offer, several levels of aggregation, or logic that needs a subquery — SuiteQL is the tool for it.
SuiteQL queries NetSuite's analytics data source. You write SELECT statements with joins, WHERE clauses, GROUP BY, HAVING and ORDER BY — the standard SQL constructs every developer knows. The difference from traditional SQL is that you're querying NetSuite's record types and fields rather than raw database tables.
SuiteQL doesn't replace saved searches. Saved searches are still better for reports that business users build and adjust, dashboard portlets, scheduled emails and alerts. But for developers building integrations, custom reports and data extraction, SuiteQL is more powerful and more readable than the equivalent saved search code.
SuiteQL syntax fundamentals
Basic SELECT
SELECT id, entityid, companyname, email
FROM customer
WHERE isinactive = 'F'
ORDER BY companynameThis returns active customers with their ID, entity ID, company name and email. The record type (customer) maps to NetSuite's Customer record. Look up table and field names in the Records Catalog (Setup > Records Catalog), which Oracle recommends for SuiteQL over the SuiteScript Records Browser.
Joins
SELECT
t.tranid,
t.trandate,
c.companyname,
t.foreigntotal
FROM transaction t
INNER JOIN customer c ON t.entity = c.id
WHERE t.type = 'SalesOrd'
AND t.trandate >= TO_DATE('2026-01-01', 'YYYY-MM-DD')
ORDER BY t.trandate DESCThis query joins transactions to customers, filtering for sales orders in 2026. SuiteQL supports inner, outer and cross joins. SuiteQL accepts both ANSI and non-ANSI joins, but not both in the same query. The examples in this guide use ANSI joins for readability; Oracle warns that SQL-92 queries can hit time-outs when NetSuite converts them, and recommends Oracle SQL syntax for production queries (see the errors section below).
Aggregations
SELECT
c.companyname,
COUNT(t.id) AS order_count,
SUM(t.foreigntotal) AS total_revenue
FROM transaction t
INNER JOIN customer c ON t.entity = c.id
WHERE t.type = 'SalesOrd'
AND t.trandate >= TO_DATE('2025-01-01', 'YYYY-MM-DD')
GROUP BY c.companyname
HAVING SUM(t.foreigntotal) > 10000
ORDER BY total_revenue DESCGROUP BY and HAVING work as expected. This gives you customer order counts and revenue totals where total revenue exceeds $10,000.
Subqueries
SELECT id, entityid, companyname
FROM customer
WHERE id IN (
SELECT entity
FROM transaction
WHERE type = 'SalesOrd'
AND trandate >= TO_DATE('2026-01-01', 'YYYY-MM-DD')
)Subqueries are supported, and they make questions like "customers who ordered this year" easy to express. Oracle's performance guidance recommends avoiding nested SELECTs where a join does the same job, so use them when the logic needs them.
Running SuiteQL queries
In SuiteScript (N/query)
The primary programmatic interface for SuiteQL is the N/query module:
define(['N/query'], function(query) {
var results = query.runSuiteQL({
query: `SELECT TOP 100 id, companyname, email
FROM customer
WHERE isinactive = 'F'`
});
var mappedResults = results.asMappedResults();
// Returns array of objects: [{id: 1, companyname: 'Acme', email: '...'}]
});The asMappedResults() method returns an array of objects with field names as keys — much cleaner than working with saved search Result objects.
query.runSuiteQL() returns at most 5,000 results and costs 10 governance units. For more, use query.runSuiteQLPaged(), which returns pages of 5 to 1,000 rows (50 by default) and needs a unique sort order.
Via REST web services
SuiteQL queries can run through SuiteTalk REST web services, which makes them useful for external integrations that pull data from NetSuite:
POST /services/rest/query/v1/suiteql?limit=10
Content-Type: application/json
Prefer: transient
{
"q": "SELECT id, companyname FROM customer WHERE isinactive = 'F'"
}The Prefer: transient header is required. Results come back 1,000 rows per page by default, up to 100,000 results per query, per Oracle's REST SuiteQL page and Collection Paging.
Since NetSuite 2026.2, REST SuiteQL also accepts anonymous bound parameters: put ? placeholders in q and send the values in a params array, which is the way to pass user input (2026.2 release notes).
POST /services/rest/query/v1/suiteql
Prefer: transient
{
"q": "SELECT * FROM item WHERE id BETWEEN ? AND ?",
"params": [ "-7", "0" ]
}Through SuiteAnalytics Connect
SuiteAnalytics Connect serves BI tools and data warehouses, and it's the route Oracle points to for results beyond the 100,000-row REST limit, using the NetSuite2.com data source. The older NetSuite.com data source is no longer available as of NetSuite 2026.1, so queries through Connect are SuiteQL (Query Language Compliance).
SuiteAnalytics Workbook can export a saved dataset definition to a SuiteQL TXT file, which is a handy starting point when you want the SQL behind a report someone built in the UI. The export is available to roles with the AnalyticsAdmin permission, and the file should be run with the same user and role used for the export (Oracle).
SuiteQL queries that won't break in production?
We write saved searches and SuiteQL queries for reports, integrations and exports, and pick the right one for each job.
Get SuiteQL helpSuiteQL vs saved searches
| Capability | Saved Searches | SuiteQL |
|---|---|---|
| Joins | Join fields to related records, as offered in the UI | Inner, outer and cross joins |
| Subqueries | Not supported | Supported |
| Aggregation | Summary types: group, sum, count, min, max, average | GROUP BY, HAVING, several levels |
| Built by business users | Yes (UI-based) | No (requires SQL) |
| Dashboard portlets | Yes (Custom Search portlet) | No |
| Scheduled emails and alerts | Yes | No (needs a script) |
| Role-based access | Yes | Yes |
| UNION queries | No | Yes |
Use saved searches when:
- Business users need to create or modify the report
- You need dashboard portlets or KPI scoreboards
- You want scheduled emails or alerts when records change
Use SuiteQL when:
- You need joins the saved search interface doesn't offer
- You need subqueries or UNION queries
- You're building integrations, exports or custom reports in code
- You need several levels of aggregation with HAVING clauses
Practical examples
Aging AR by customer
SELECT
c.companyname,
SUM(CASE WHEN CURRENT_DATE - t.duedate BETWEEN 0 AND 30 THEN t.foreignamountremaining ELSE 0 END) AS current_30,
SUM(CASE WHEN CURRENT_DATE - t.duedate BETWEEN 31 AND 60 THEN t.foreignamountremaining ELSE 0 END) AS days_31_60,
SUM(CASE WHEN CURRENT_DATE - t.duedate BETWEEN 61 AND 90 THEN t.foreignamountremaining ELSE 0 END) AS days_61_90,
SUM(CASE WHEN CURRENT_DATE - t.duedate > 90 THEN t.foreignamountremaining ELSE 0 END) AS over_90
FROM transaction t
INNER JOIN customer c ON t.entity = c.id
WHERE t.type = 'CustInvc'
AND t.foreignamountremaining > 0
GROUP BY c.companyname
ORDER BY c.companynameTop items by units sold
SELECT TOP 20
i.itemid,
i.displayname,
SUM(tl.quantity * -1) AS units_sold
FROM transactionline tl
INNER JOIN transaction t ON tl.transaction = t.id
INNER JOIN item i ON tl.item = i.id
WHERE t.type = 'SalesOrd'
AND t.trandate >= TO_DATE('2025-01-01', 'YYYY-MM-DD')
AND tl.mainline = 'F'
AND tl.taxline = 'F'
GROUP BY i.itemid, i.displayname
ORDER BY units_sold DESCSales order lines store quantity as a negative value, which is why this query multiplies it by -1. Check the sign of any amount field the same way before you total it.
Customers without orders in 6 months
SELECT c.id, c.companyname, c.email
FROM customer c
WHERE c.isinactive = 'F'
AND c.id NOT IN (
SELECT DISTINCT t.entity
FROM transaction t
WHERE t.type = 'SalesOrd'
AND t.trandate >= ADD_MONTHS(CURRENT_DATE, -6)
)
ORDER BY c.companynameCommon SuiteQL errors and how to fix them
Oracle's SuiteQL pages document limits more often than they quote error text. Where a message below is quoted, the source is linked; where a limit has no published message, the entry describes the symptom instead.
"Invalid search query": an unknown table, column or field
A query that names a table or column SuiteQL doesn't expose is rejected with "Invalid search query". Coupler.io's NetSuite troubleshooting guide lists the usual causes: a syntax error, an unknown table or column name, or a field that doesn't exist on that record.
The most common root cause is borrowing names from saved searches. N/query uses a different data source than N/search, so Oracle tells you to look up record types and field IDs in the Records Catalog, not the SuiteScript Records Browser (N/query module). Availability also depends on the features enabled and the permissions your role holds; the catalog hides unavailable items unless you turn on "Show Unavailable Items", and a field marked "N/A (Only for join)" can be joined on but not selected as a column (Records Catalog).
Fix: copy the name from Setup > Records Catalog, then probe the record before writing the full query. Oracle's own syntax page uses this pattern:
SELECT TOP 10 * FROM transactionCustom fields have one more documented gap: Oracle notes that data from custom fields isn't listed with the Analytic APIs, so a query on a custom transaction body field won't return the information from its subtabs in the UI (SuiteQL Limitations and Exceptions).
"Your current role does not have permission to perform this action."
Over REST this arrives as HTTP 400. Improvado's NetSuite troubleshooting guide explains that NetSuite accepted the token but the role isn't allowed to use REST at all. Fix: enable REST Web Services, your authentication method and SuiteAnalytics Workbook under Setup > Company > Enable Features; give the role the matching login permission (for token-based authentication, "Log in using Access Tokens"), REST Web Services and SuiteAnalytics Workbook; then grant View on the records you query. Regenerate the token afterwards.
If the call succeeds but a specific record fails with 403 or "insufficient permission", Coupler.io's guide traces that to a role without view permission on that record type. This follows from the design: SuiteQL enforces the same role-based access restrictions as SuiteAnalytics Workbook. In SuiteScript, metaDataProvider controls the behaviour: by default (SUITE_QL) the query fails if you touch fields or records you lack permission for, while STATIC lets it succeed and returns no data for those fields (runSuiteQL reference). If a SuiteQL or REST build keeps stalling on roles and limits, our NetSuite development team writes SuiteQL queries, RESTlets and integrations.
Exactly 5,000 rows back, or duplicate and missing rows across pages
query.runSuiteQL() returns a maximum of 5,000 results, and Oracle's answer is query.runSuiteQLPaged() (reference). The paged method has its own rules, per its reference page: a page size of 5 to 1,000 (default 50), a maximum of 1,000 pages, and a maximum of 100,000 results across all pages unless SuiteAnalytics Connect is enabled. Oracle also states that you must give the query "a unique and unambiguous sorting order" to avoid duplicate or missing results.
var pagedData = query.runSuiteQLPaged({
query: "SELECT id, tranid FROM transaction WHERE type = 'SalesOrd' ORDER BY id",
pageSize: 1000
});
// Iterate the page ranges and fetch each pageSort on a unique column such as id, or add id as the last sort key.
REST queries stop at 100,000 results
Oracle's REST page says a SuiteQL query can return a maximum of 100,000 results and points to SuiteAnalytics Connect with the NetSuite2.com data source beyond that. Coupler.io reports that larger queries fail rather than return partial data. Fixes:
- Page with
limitandoffset. The default is 1,000 results per page on a maximum of 1,000 pages, the offset must be divisible by the limit (offset 20 with limit 10 works), and thehasMorefield tells you whether another page exists (Collection Paging). - Split the extract into batches. Oracle's performance guidance recommends batches, with this example:
SELECT id, lastmodifieddate, tranid
FROM transaction
WHERE id >= 10000000 AND id < 20000000An IN list with more than 1,000 values
Oracle's rule: "You can't use more than 1000 arguments in a single IN clause" (performance and best practices). Fix: stop passing IDs from your application. Select them with a subquery or join, or run the lookup in batches of fewer than 1,000.
SELECT id, companyname
FROM customer
WHERE id IN (SELECT entity FROM transaction WHERE type = 'SalesOrd')Time-outs and mixed join syntax
Oracle warns that "although SuiteQL supports ANSI SQL-92, there's a risk of critical performance issues, such as time outs that aren't operationally remediable" when a SQL-92 query is converted to SQL, and recommends Oracle SQL syntax (SuiteQL syntax and examples). Related documented rules from the performance page:
- You can't mix ANSI and non-ANSI join syntax in one query.
- Oracle-style outer joins with
(+)are not valid; use ANSI syntax for outer joins. - Don't put quotation marks around field names in subselections.
- Avoid too many joins, repeating the same join to a table, and complex nested SELECTs.
TOPcan affect performance, because SuiteQL runs against a virtual schema.
The same join in Oracle syntax:
SELECT t.tranid, c.companyname
FROM transaction t, customer c
WHERE t.entity = c.id
AND t.type = 'SalesOrd'Functions SuiteQL rejects
SuiteQL only runs functions on its supported list, which is how it blocks SQL injection. Oracle's supported and unsupported functions page names these common ones as unsupported, with the alternative:
| Unsupported | Use instead |
|---|---|
SUBSTRING, LEFT, RIGHT | SUBSTR |
CHARINDEX, LOCATE, POSITION | INSTR |
CHAR_LENGTH, CHARACTER_LENGTH | LENGTH |
LCASE, UCASE | LOWER, UPPER |
CEILING | CEIL |
LISTAGG, DATEDIFF | No alternative listed |
Oracle says the list is not exhaustive. Date work uses functions on the supported list, including TO_DATE, ADD_MONTHS, CURRENT_DATE, TRUNC and MONTHS_BETWEEN.
Built-in functions: the BUILTIN. prefix and required parameters
To use a built-in function, "you must add BUILTIN. before the function name", and every parameter not marked optional is required (Oracle). BUILTIN.DF returns the display value of a field without an explicit join (reference). BUILTIN.CONSOLIDATE takes seven parameters: amount field, view type ('LEDGER' or 'INCOME'), consolidation rate type, subsidiary rate type, target subsidiary, period and book. You can pass 'DEFAULT' for any of them except the amount field and the view type (reference).
Oracle's syntax example for the display-value function, where the argument is the relationship between the field and its source record:
BUILTIN.DF(sales.item)Oracle publishes no error text for malformed built-in calls.
The same query returns rows in a different order after 2026.2
This one raises no error. Per the 2026.2 release notes, SuiteQL queries and Analytics datasets based on generic transactions now use Transaction.tranDate as the default sort field when no sort order is specified; they previously used Transaction.tranDisplayName. Queries that specify a sort order are not affected. Fix: add an ORDER BY wherever order matters.
SELECT id, tranid, trandate
FROM transaction
WHERE type = 'SalesOrd'
ORDER BY trandate DESC, id DESCOther documented limits that look like bugs
From SuiteQL Limitations and Exceptions:
- Square brackets
[ ]are not supported. - Result keys and aliases come back lowercase: an alias of
myIDappears asmyid. Don't depend on name casing in results. - Sorting on a CLOB field evaluates only the first 250 characters of each value.
BUILTIN.HIERARCHY(PARENT, 'LEVEL')can return a level of n-1 instead of n in some cases.- Conditions on
TranTypeforTransactionStatusrecords can return unexpected results; Oracle's workaround isWHERE TranType LIKE 'CuTrSale%'.
Habits that avoid most of the above
Transaction lines require explicit mainline filtering. Each transaction has a mainline row (summary) and detail rows (line items). Filter with mainline = 'F' for line items or mainline = 'T' for the summary row, and exclude tax lines with taxline = 'F'.
Convert date strings with TO_DATE(). It is on the supported function list, and the examples in this guide use it for every date comparison.
Cap queries while you develop. SELECT TOP 100 while you iterate, and the REST limit parameter for paged results.
Getting started
Start with the Records Catalog to understand the data model. Pick a saved search you know well and rewrite it in SuiteQL — that gives you a reference point where you know what the correct output should look like.
Then move to the queries saved searches can't handle: joins the UI doesn't offer, subqueries, UNION and several levels of aggregation. That's where SuiteQL earns its place.
What clients ask before signing
Gustavo · BrokenRubik
Replies by email within 24 hours
Gustavo
Stuck on a script, a query or an API call? Paste the error and a developer will reply with what we'd check first.

Joaquin Vigna
Co-Founder & CTO
Co-founder and Chief Technology Officer at BrokenRubik with 12+ years of experience in software architecture and NetSuite development. Leads technical strategy, innovation initiatives, and ensures delivery excellence across all projects.
