Editing text of a query with sub-queries and unions on the Query Builder tab

Last modified:


FlySpeed SQL allows you to browse, edit sub-queries in a complex query (and preview their results) separately from the main query. The "Text" and "Preview" tabs below the visual query builder are designed for this purpose.

You can choose one of the following modes by clicking on the "Sub-query edit mode" button at the right of the text editor:

Image

The "Edit sub-query with unions" mode is set by default. This mode allows you to edit sub-queries in expressions, CTE and derived tables separately from the main query, but if a sub-query contains set operators (UNION, EXCEPT, INTRESECT), it will be displayed as whole. If you want to edit these statements separately, you should switch to the "Edit single SELECT sub-query" mode. The "Edit whole query" mode turn this feature off.

Editing a sub-query you'll see your position in a query on the breadcrumbs bar above the text editor:Image

 

 

Important notice about the "Edit single SELECT sub-query" mode:

 

This mode allows you to edit each sub-query in a list of sub-queries united with set operators (UNION, EXCEPT, INTERSECT, MINUS) separately. So, in the Text tab under the visual query builder control, you'll see single select statement only.

This means that when you have a query like this:

 

Select * From ABC
UNION All
Select * From BCD

 

You'll see only the first or the second sub-query on the Text tab:

Image

 

You are not only browsing, but you can edit this sub-query and changes will be applied to the whole query.

But this means that you can not type a sub-query containing other union sub-queries in this mode as you'll get the "SQL must be simple SELECT" error. I know that this is inconvenient, that's why we've choosen the "Edit sub-query with unions" mode as default.

So you can either switch to default mode and type a query with unions then, or you can go to the SQL Text tab:

Image

There you will see the whole query regardless of the mode on the Query Builder tab.


This article was helpful for 1 person. Is this article helpful for you?