Atlassian uses cookies to improve your browsing experience, perform analytics and research, and conduct advertising. Accept all cookies to indicate that you agree to our use of cookies on your device. Atlassian cookies and tracking notice, (opens new window)
Teams
, (opens new window)

One Appfire Support Knowledge Base
Results will update as you type.
  • License-related documentation
  • Product Categories
    • Administrative Tools
    • BI and Reporting Apps
      • Rich Filters for Jira Dashboards App
      • Rich Filters Support
      • Arsenale Dataplane
      • Power Dashboard Reports and Gadgets Knowledge Base
      • Dashboard Hub KB - Ronin Pixels
      • Charts & Graphs for Bitbucket
      • Tableau Connector Pro for Jira
      • Power BI Connector Pro for Jira
      • Database Exporter for Jira Cloud
      • Reports and Timesheets for Jira
      • Excel for Confluence (XL)
      • SQL for Confluence (SQL)
        • How to find all pages that use SQL for Confluence (Pro Edition) macros via database
        • Troubleshooting the user permissions issue in the SQL Query Macro using the SQL for Confluence App
        • SQL for Confluence app gets disabled when upgraded to v10.4.1
        • How to find the memory consumed by database tables using SQL for Confluence app
        • Add Profile for Microsoft SQL Server using SQL for Confluence
        • How to convert text to hyperlinks using SQL queries with SQL for Confluence
        • How to get usage information of an app being used in space templates
        • How to retrieve data with single quotes from Oracle database fields
        • How to display links in SQL results using SQL for Confluence
        • How to resolve an Access denied error - 10.x
        • How to add queries within queries
        • How to resolve an Authentication failed error - 10.x
        • How to avoid format errors when using output=wiki
        • How to resolve broken database connections - 10.x
        • How to resolve a Class not found error - 10.x
        • How to combine queries from multiple databases
        • How to update database columns and display them in a page using Run macro with SQL macro
        • Configure application server based datasources - 10.x
        • Configure data source profiles 10.x
        • How to resolve an Invalid syntax server.xml error
        • How to resolve a Could not create connection to database server error - 10.x
        • Create a chart with SQL - 10.x
        • How to resolve a Data source name not found error - 10.x
        • How to resolve a Database server not found error - 10.x
        • Datasource problem determination - 10.x
        • Example profile configurations
        • Error while retrieving the data using SQL for Confluence
        • How to resolve a Generic SQL exception - 10.x
        • How to find pages that uses a specific data source profile in different SQL macros
        • How to get favorites list of Confluence users using Sql for Confluence
        • How to configure data source profiles for various databases with examples
        • How to do data source problem determination
        • How to handle the "No suitable driver found" error when connecting to an MS-SQL database
        • How to hyperlink the SQL macro results
        • How to implement role based security for SQL queries - 8.x
        • How to improve the display of SQL source - 8.x
        • How to show all table rows using a nested query with SQL for Confluence
        • How to implement role based security for SQL queries - 10.x
        • How to improve the display of SQL source - 10.x
        • How to index SQL data
        • How to use SQL data with inline macros
        • How to resolve a Listener refused connection error - 10.x
        • How to log SQL activity
        • Pro tips
        • How to publish SQL queries on Atlassian Cloud
        • How to run SQL queries securely without page edit restrictions
        • Sample Queries - Confluence Labels
        • How to resolve the Unable to load database driver error
        • How to use Confluence metadata in SQL queries
        • How to use HTML in queries
        • How to use SQL case statement to improve the visual appeal
    You‘re viewing this with anonymous access, so some content might be blocked.
    /
    How to add queries within queries
    Updated Feb 27, 2020

    How to add queries within queries

    Feb 27, 2020

    On this page

    Description

    To improve how you show data to viewers, you can employ some advanced techniques by including queries within other queries. This also allows you to incorporate data from multiple data sources into a single table.

    The example on this page demonstrates a number of advanced techniques using this approach. The example uses two inner SQL Query macros with queries that depends on the data provided by the outer query. Although not shown here, this technique can drive a query from another data source just as easily as from the same data source. Those queries can produce tables, as illustrated here, or a single value by using table=false in the wiki markup for the inner query.

    To know more about SQL Query macros, click the relevant version:

    • 10.x version

    • 8.x version

    Example

    Result view

    Edit view

    SQL text

    SQL Query
    select '{sql-query:dataSource=exampleDataDS|output=wiki|rowOrientation=horizontal} select "Customer Number" as "Number" , "Customer Name" as "Name" , "Country" , "Credit Limit" , (select employees."First Name" || '' '' || employees."Last Name" from employees where customers."Sales Rep Employee Number" = employees."Employee Number") as "Sales Rep" from customers where customers."Customer Number" = ' || orders."Customer Number" || ' {sql-query}' as "Customer" , date("Order Date") as "Order Date" , date("Required Date") as "Required Date" , date("Shipped Date") as "Shipped Date" , case when "Status" = 'Cancelled' then '{status:color=red|title=' || "Status" || '}' when "Status" = 'Shipped' then '{status:color=green|title=' || "Status" || '}' else '{status:color=yellow|title=' || "Status" || '}' end as "Status" , "Order Number" , '{sql-query:dataSource=exampleDataDS|autoTotal=true|autoNumber=true|columnTypes=S,I,S,F|columnAttributes=,,style=text-align: right} select "Product Code" as "Product" , "Quantity Ordered" as "Quantity" , "Unit Price" , round("Quantity Ordered" * "Unit Price", 2) as "Total Price" from orderdetails where orderdetails."Order Number" = ' || orders."Order Number" || ' order by orderdetails."Order Line Number"{sql-query}' as "Order Details" from orders order by "Order Date" desc limit 75
    {"serverDuration": 14, "requestCorrelationId": "d2de837bc86b4f889cb09805d22afc3d"}