Use the power of SQL to run queries in Excel and directly on Excel tables

Often Excel tables gradually grow into large inconvenient workbooks. Finding duplicates, filtering, grouping, complex sorting, joining tables into one, etc. – become a real challenge. Potentially, these tasks could be easily executed with SQL… if only it were possible to run SQL queries against Excel data.

XLTools SQL Queries add-in enhances Excel with the power of structured query language:

  • Run SQL queries in Excel interface and directly on Excel tables
  • Generate SELECT and JOIN statements automatically
  • Use JOIN, ORDER BY, DISTINCT, GROUP BY, SUM and other SQLite operators
  • Write queries in the intuitive editor with syntax highlighting
  • Address any Excel tables from a tree list view
Screenshot: main features of XLTools SQL Queries

How to turn your Excel data into a relational database and prepare for SQL querying

By default, Excel presents data as simple data ranges. But SQL works only with relational data sources. So before you begin, make sure to format Excel ranges as tables (named ranges with table style applied):

  1. Select the data range On the Home tab clickFormat as Table Select a table style.
  2. Select the table Open the Design tab Type in the Table Name.

    E.g. "ProductID"

  3. Repeat these steps for each data range that you plan to use in SQL queries.

    E.g. tables "RetailPrice", "SalesVolume", etc.

  4. Done, now these tables will serve as a relational database and are prepared for querying.
How to turn Excel data into relational database before running sql queries

How to create and run SQL SELECT on Excel tables

SQL Queries add-in allows you to execute queries on Excel tables located in different worksheets and different workbooks. Please make sure that these workbooks are open and the necessary data are formatted as named tables.

  1. Click theExecute SQLbutton on the XLTools tab The editor window will open.
  2. On the left-hand side find a tree view of all available tables.

    Click on the nodes to expand/collapse table fields (columns).

  3. Select entire tables or specific fields.

    As you tick the fields, SELECT statement is generated automatically in the right-hand side area of the editor.
    Tip:watch the SQL editor automatically highlight syntax.
  4. Choose whether to place the query output on a new or an existing worksheet.
  5. Click Run Done!
How to generate SELECT statement with XLTools SQL Queries

Operators Left Join, Order By, Group By, Distinct, and other SQLite commands in Excel

XLTools usesSQLite syntax. Users who are familiar with SQLite can execute a wide variety of queries:

  • LEFT JOIN – join two or more tables by shared key columns
  • ORDER BY – sort data in query results
  • DISTINCT – remove duplicates from the query output
  • GROUP BY – group data in query results
  • SUM, COUNT, MIN, MAX, AVG and other operators
Tip:watch the SQL editor automatically highlight syntax.

How to join two or more Excel tables with SQL Queries add-in

You can merge multiple Excel tables into one if they have a shared key field. Suppose you have to join a few tables that share a column "ProductID":

  1. ClickExecute SQLon XLTools tab Select the fields you want to see in the merged table.

    As you tick the fields, SELECT and LEFT JOIN get generated automatically.

  2. Choose whether to place the query output on a new or an existing worksheet.
  3. Click Run Done! A merged table appears in seconds.
How to left join Excel tables with XLTools SQL Queries add-in
Any questions or suggestions?
close window
How can we help?