Creating and Editing a Query

This topic explains how to create and edit an SQL query in Query Builder for MySQL.

To create a query:

  1. Create a server connection.

  2. On the Standard toolbar, click New SQL.

  3. In the SQL document that opens, type a query to a database.

  4. To execute the query, click Execute or press CTRL+F5.

Coding Techniques Example

The Query Builder for MySQL editor provides many features that make it easier for you to write and manage your code. Let’s explore some Intellisense features that assist you while coding.

We are going to create a sample query. In this example we will use the sakila database to display all the films stored in the sakila database, that were released after 2004.

To create a query, follow the steps:

  1. Open SQL Editor.

  2. Start typing the SELECT statement by entering the first three letters sel. Query Builder for MySQL shows you the SELECT keyword in the drop-down list. To select it, press ENTER.

    SELECT

  3. Type * to select all values and start typing f. Query Builder for MySQL shows you the FOR and FROM keywords in the list.

    SELECT from

  4. Type a table name from which the data will be retrieved. The film table comes first on the list, so just press TAB or ENTER to insert it into the SQL editor.

  5. We need to select films categories that are stored in a separate table. In a similar way, type the JOIN keyword and press the space. Query Builder for MySQL shows you all available solutions to implement JOIN. Select required statement and press ENTER.

    The film_category table is displayed on the list, so just press TAB or ENTER to insert it into the SQL editor.

    JOIN

  6. Continue typing the query. You can use the Quick Info feature while typing SQL code. The Quick Info feature is a tooltip with brief information about database objects, parameters, and variables. The tooltip appears when you hover over the required item in the SQL script.

    Quick Info

    In case of database objects, the tooltip shows their location and types. You will find this option useful, while working with large scripts.

    Quick Info

  7. To format the query text, use the CTRL+D combination. Now we can execute the query to see results. To do so, click Execute button Execute or press F5.

  8. Now, we need to add the WHERE condition, WHERE release_year > 2004, at the end of the query and press F5 to execute it.

    Result of the query

As you can see the code completion feature provided by Query Builder for MySQL allows you to create complex queries in a few keystrokes.