How to create a SQL query in Query Builder
Last modified: October 1, 2024
This topic explains how to create and edit an SQL query in dbForge Studio for SQL Server using the Query Builder functionality.
We are going to create a sample query by using visual query designer. We will use the AdventureWorks2012 database. Assume we need to display all the employees whose total sales result for the preceding year is greater than 2 000 000.
To create a query visually:
- Create a server connection. For more information about how to create a server connection see How To: Connect to a Database.
- On the Start page click SQL Development and then click Query Builder.
-
Drag-and-drop tables from Database Explorer to the editor. Holding CTRL, select the Person table and the SalesPerson table, and drag-and-drop them over to the visual editor.
- Select the FirstName and LastName check-boxes in the Person table, and the SalesLastYear check-box in the SalesPerson table.
-
Create a relationship between tables based on the BusinessEntityID primary key. To do this, select BusinessEntityID in the Person table and drag it over the BusinessEntityID in the SalesPerson table.
-
On the Where tab, insert the condition. Click the green plus icon.
-
Click enter value. In the Table drop-down list select the SalesPerson table, and then select the SalesLastYear column.
-
Click the equals sign and select greater than instead.
-
Click enter value and type 2 000 000.
-
On the Group By tab select columns you want to group by the output data.
-
On the Order By tab select the sort order.
-
Finally, the visual query will look as follows:
-
Press F5 to execute the query.
-
You can also view and edit (if needed) the generated automatically SQL code.
In this topic we reviewed quite simple query, however it demonstrates the convenience of the approach on creating queries visually.
Visual query editor will save a lot of your time in case of more complex queries to multiple tables and views.
Download dbForge Studio for SQL Server and try it absolutely free for 30 days!
Want to find out more?
Overview
Take a quick tour to learn all about the key benefits delivered by dbForge Studio for SQL Server.
All features
Get acquainted with the rich features and capabilities of the tool in less than 5 minutes.
Request a demo
If you consider employing this tool for your business, request a demo to see it in action.