SELECT Queries
Syntra ODBC supports standard SQL SELECT syntax for reading QuickBooks data. Queries run against the local cache by default, with the option to force live fetches from QuickBooks.
Basic SELECT
Section titled “Basic SELECT”SELECT * FROM customers;
SELECT name, phone, email, balanceFROM customers;WHERE Clauses
Section titled “WHERE Clauses”Filter rows using standard comparison operators:
SELECT name, balanceFROM customersWHERE balance > 1000;
SELECT * FROM invoicesWHERE txn_date >= '2025-01-01' AND is_paid = false;
SELECT * FROM item_inventoriesWHERE name ILIKE '%widget%';Supported Operators
Section titled “Supported Operators”| Operator | Example |
|---|---|
=, !=, <> | WHERE is_active = true |
<, >, <=, >= | WHERE balance >= 500 |
LIKE / ILIKE | WHERE name ILIKE '%corp%' |
IN | WHERE ref_number IN ('INV-001', 'INV-002') |
BETWEEN | WHERE txn_date BETWEEN '2025-01-01' AND '2025-12-31' |
IS NULL / IS NOT NULL | WHERE email IS NOT NULL |
AND, OR, NOT | WHERE balance > 0 AND is_active = true |
ORDER BY
Section titled “ORDER BY”Sort results by one or more columns:
SELECT name, balanceFROM customersORDER BY balance DESC;
SELECT * FROM invoicesORDER BY txn_date DESC, ref_number ASC;LIMIT and OFFSET
Section titled “LIMIT and OFFSET”Restrict the number of returned rows:
SELECT * FROM customersORDER BY nameLIMIT 50;
SELECT * FROM customersORDER BY nameLIMIT 50 OFFSET 100;GROUP BY and Aggregates
Section titled “GROUP BY and Aggregates”Use aggregate functions with GROUP BY:
SELECT customer_ref_full_name, COUNT(*) AS invoice_count, SUM(balance_remaining) AS total_owedFROM invoicesGROUP BY customer_ref_full_nameORDER BY total_owed DESC;Supported Aggregate Functions
Section titled “Supported Aggregate Functions”COUNT(*),COUNT(column),COUNT(DISTINCT column)SUM(column)AVG(column)MIN(column),MAX(column)
Examples
Section titled “Examples”-- Total customersSELECT COUNT(*) AS total_customers FROM customers;
-- Invoice totalsSELECT SUM(subtotal) AS total, AVG(subtotal) AS average FROM invoices;
-- Revenue by customerSELECT customer_ref_full_name, COUNT(*) AS invoice_count, SUM(subtotal) AS revenue, AVG(subtotal) AS avg_invoiceFROM invoicesGROUP BY customer_ref_full_nameORDER BY revenue DESC;
-- Monthly invoice summarySELECT DATE_TRUNC('month', txn_date) AS month, COUNT(*) AS invoices, SUM(subtotal) AS totalFROM invoicesGROUP BY monthORDER BY month;HAVING
Section titled “HAVING”Filter groups after aggregation:
SELECT customer_ref_full_name, SUM(balance_remaining) AS total_owedFROM invoicesGROUP BY customer_ref_full_nameHAVING SUM(balance_remaining) > 5000ORDER BY total_owed DESC;Column Aliases
Section titled “Column Aliases”SELECT name AS "Customer", balance AS "Amount Owed", phone AS "Phone Number"FROM customers;DISTINCT
Section titled “DISTINCT”Remove duplicate rows:
SELECT DISTINCT customer_ref_full_nameFROM invoicesWHERE txn_date >= '2025-01-01';CASE Expressions
Section titled “CASE Expressions”SELECT name, balance, CASE WHEN balance = 0 THEN 'Paid' WHEN balance < 1000 THEN 'Low' ELSE 'High' END AS balance_categoryFROM customers;Column Metadata and Data Types
Section titled “Column Metadata and Data Types”Every column returned by a query has a Syntra SQL type with a numeric type code. You can inspect column types using the Query Explorer’s hover tooltips (hover over any column header) or the Copy Schema JSON button. See the Syntra SQL Type Reference for what each code means.
Schema JSON Example
Section titled “Schema JSON Example”Running SELECT list_id, name, full_name, email, phone, balance FROM customers LIMIT 5 and clicking Copy Schema JSON produces:
[ { "name": "list_id", "type": "varchar", "oid": 1043 }, { "name": "name", "type": "varchar", "oid": 1043 }, { "name": "full_name", "type": "varchar", "oid": 1043 }, { "name": "email", "type": "varchar", "oid": 1043 }, { "name": "phone", "type": "varchar", "oid": 1043 }, { "name": "balance", "type": "numeric", "oid": 1700 }]Data Type Reference
Section titled “Data Type Reference”Syntra ODBC maps QuickBooks field types to standard PostgreSQL types:
| OID | PG Type | Description | QuickBooks Examples |
|---|---|---|---|
| 1043 | varchar | Variable-length string | Names, IDs, addresses, memos |
| 1700 | numeric | Decimal with precision/scale | Balance, subtotal, rate, amount |
| 23 | int4 | 32-bit integer | TxnNumber, counts |
| 20 | int8 | 64-bit integer | COUNT(*) results |
| 16 | bool | Boolean (true/false) | IsActive, IsPaid, IsPending |
| 1082 | date | Calendar date | TxnDate, DueDate, ShipDate |
| 1114 | timestamp | Date + time | TimeCreated, TimeModified |
Querying Column Metadata
Section titled “Querying Column Metadata”You can also query column metadata directly via SQL:
-- List all columns for a tableSHOW COLUMNS FROM customers;
-- Detailed column info via information_schemaSELECT column_name, data_type, ordinal_positionFROM information_schema.columnsWHERE table_name = 'invoices'ORDER BY ordinal_position;
-- Column metadata via pg_catalog (includes type OIDs)SELECT attname, typname, atttypidFROM pg_catalog.pg_attribute aJOIN pg_catalog.pg_class c ON trueWHERE c.relname = 'customers';Table Index
Section titled “Table Index”Syntra ODBC exposes 121 QuickBooks tables. Here are the most commonly queried:
Customers & Receivables
Section titled “Customers & Receivables”| Table | Key Column | Description |
|---|---|---|
customers | list_id | Customer records with contact info and balance |
invoices | txn_id | Sales invoices |
invoice_lines | txn_line_id | Line items on invoices (linked by txn_id) |
credit_memos | txn_id | Credit memos |
estimates | txn_id | Estimates / quotes |
sales_receipts | txn_id | Sales receipts (immediate payment) |
sales_orders | txn_id | Sales orders |
receive_payments | txn_id | Payments received |
Vendors & Payables
Section titled “Vendors & Payables”| Table | Key Column | Description |
|---|---|---|
vendors | list_id | Vendor records |
bills | txn_id | Bills from vendors |
purchase_orders | txn_id | Purchase orders |
bill_payment_checks | txn_id | Bill payments by check |
bill_payment_credit_cards | txn_id | Bill payments by credit card |
Items & Inventory
Section titled “Items & Inventory”| Table | Key Column | Description |
|---|---|---|
item_inventories | list_id | Inventory items with quantity on hand |
item_non_inventories | list_id | Non-inventory items |
item_services | list_id | Service items |
item_other_charges | list_id | Other charge items |
item_discounts | list_id | Discount items |
item_groups | list_id | Group items |
item_sales_taxes | list_id | Sales tax items |
Banking & General Ledger
Section titled “Banking & General Ledger”| Table | Key Column | Description |
|---|---|---|
accounts | list_id | Chart of accounts |
checks | txn_id | Checks written |
deposits | txn_id | Bank deposits |
journal_entries | txn_id | Journal entries |
currencies | list_id | Currency definitions |
Reference
Section titled “Reference”| Table | Key Column | Description |
|---|---|---|
classes | list_id | Class tracking categories |
employees | list_id | Employee records |
payment_methods | list_id | Payment method types |
ship_methods | list_id | Shipping methods |
customer_types | list_id | Customer type categories |
vendor_types | list_id | Vendor type categories |
sales_tax_codes | list_id | Sales tax codes |
Use SHOW TABLES; to see the complete list of all 121 tables.
Common Query Patterns
Section titled “Common Query Patterns”Customer Aging Report
Section titled “Customer Aging Report”SELECT c.full_name, c.balance, COUNT(i.txn_id) AS open_invoices, MIN(i.txn_date) AS oldest_invoice, MAX(i.txn_date) AS newest_invoiceFROM customers cLEFT JOIN invoices i ON i.customer_ref_list_id = c.list_id AND i.is_paid = falseWHERE c.balance > 0GROUP BY c.full_name, c.balanceORDER BY c.balance DESC;Top Selling Items
Section titled “Top Selling Items”SELECT il.item_ref_full_name, COUNT(*) AS times_sold, SUM(il.quantity) AS total_qty, SUM(il.amount) AS total_revenueFROM invoice_lines ilGROUP BY il.item_ref_full_nameORDER BY total_revenue DESCLIMIT 20;Unpaid Invoices with Customer Details
Section titled “Unpaid Invoices with Customer Details”SELECT i.ref_number, i.txn_date, i.due_date, c.full_name, c.phone, i.balance_remainingFROM invoices iINNER JOIN customers c ON i.customer_ref_list_id = c.list_idWHERE i.is_paid = false AND i.balance_remaining > 0ORDER BY i.due_date ASC;Revenue by Month
Section titled “Revenue by Month”SELECT DATE_TRUNC('month', txn_date) AS month, COUNT(*) AS invoice_count, SUM(subtotal) AS gross_revenue, SUM(sales_tax_total) AS tax_collected, SUM(balance_remaining) AS outstandingFROM invoicesWHERE txn_date >= '2025-01-01'GROUP BY monthORDER BY month;Inventory Valuation
Section titled “Inventory Valuation”SELECT full_name, quantity_on_hand, average_cost, quantity_on_hand * average_cost AS total_valueFROM item_inventoriesWHERE is_active = true AND quantity_on_hand > 0ORDER BY total_value DESC;Forcing a Live Query
Section titled “Forcing a Live Query”By default, SELECT queries read from the local cache. To force a live fetch from QuickBooks:
SET QB_MAX_STALENESS = 0;SELECT * FROM customers WHERE list_id = '80000001-1234567890';See Special Commands for more details on cache control.