Querying a results set ("Save as query view")

Ever wanted to “query a query”? In other words, take some results and use that as the basis for another query?

Omni’s “Save as query view” feature is built for exactly that :smiley: Once you save your results as a query view, you can interact with it just like any other table you access in Omni — you can query it, join it, add it to Topics, etc.

If you’re familiar with SQL, it’s similar to writing some SQL, stuffing it into a CTE, and then writing more SQL on top of it. Except in Omni, you can do it all with your cursor, and re-use the base query elsewhere!

A quick video walkthrough

Using “Save as query view” (with the UI)

Once you’ve created the results set you want, navigate to “Model” in the top nav > “Save as query view.”

Give your query a name:

You’ll enter this “Query view” UI, where you can adjust the query view as you like. Once you’re ready, hit “Use in query.”

Using “Save as query view” (with SQL)

Sometimes, you just want to write SQL instead of using Omni’s UI to build the query. This is especially useful for building more complex queries, such as window functions.

For this, simply open a SQL tab in your workbook, and write SQL just like how you would against the database. When you’re happy with your results, you can click “Save as query view” in the top right corner of the tab page.

Using the Query View

From here, you can simply click “Use in query” from the View tab, to query directly on top of your Saved View

You’ll also see your new query in “All views & fields”. It’s just like any other table coming from your database; you can query it, join it, add it to Topics, etc. You can even open the SQL tab to ensure that it captured the logic you intended to.

You’ll often want to join it to the data you were working with already. Omni’s smart and will automatically create a join to the base table of the query it was built from.

So you can head back to your original query tab, open the join module from the original table, and then add in your new “query view” to the Topic:

Query view use cases