Building a SQL Query
The Visual SQL Query editor can be used to easily create complex SQL queries without having to remember complex SQL syntax. Visually add tables, create joins, manage groups, expressions and order your output with easy-to-use wizards. In this tutorial, you will learn how to:
- Open the Visual SQL Query editor
- Add tables to the query and create a join
- Build an expression
- Run the SQL
This feature is available in MyEclipse.
1. Open the Visual SQL Query Editor
There are several ways to access the Visual SQL Query editor.
1.1 Opening from the SQL Editor
Right-click the SQL editor, and select Open in MyEclipse Visual SQL Query Editor. When you finish with the Visual SQL Query editor, the query you created is inserted into the SQL editor, replacing the selected query, if any.
Opening the Visual SQL Query editor
1.2 Opening Existing SQL Files
Right-click a SQL file, and click Open With>MyEclipse Visual SQL Query Editor.
Opening a SQL file in the Visual SQL Query editor
1.3 Opening from a Database Connection
Right-click a connection in the DB Browser, and select New Visual SQL Query Editor.
Opening the Query editor from a connection
2. Add Tables to a Query and Create Joins
- Right-click the editor, and select Add Table.
Adding a table to the query
- Select a table, and click OK to use it in your query.
Selecting a table to add to the query
- Drag from one column to another to create a join between the two.
Creating a join
3. Build Expressions for Your Output
- Select Build Expression from the Column drop-down.
Building an expression so results display in output
- Choose the type of expression you want to build.
Selecting an expression type
This example uses the SUM function to return the sum of the AMOUNT column in the PAYMENT table.
SUM function example
- Use the Groups tab to group the results by the CUSTOMERNAME column.
Grouping results by CUSTOMERNAME
4. Run the Query
The image below depicts the finished query. To execute this, right-click the source view, and select Run SQL.
Results are displayed in the SQL Results view.
Results of running the query