access_time 5 MIN | fiber_manual_record EXPERT | label TRAINING, STYLING, FUNDAMENTALS, BASIC MAP STYLING, CUSTOM MAP STYLING, SQL QUERIES EXPLAINED
For more advanced editing of your data, the Mapbuilder contains a SQL window in the data window. To get here you can click the ‘SQL’ button on the right side.
When clicked it opens a SQL window on the left side where you can work with different PostgreSQL and PostGIS queries.
A SQL query is build up by multiple parts in a standard order. The next part will give you a basic explanation of SQL queries so you can run these basic queries in the Mapbuilder. Note that the explanation we give in this tutorial only shows you the basics of SQL. Google ‘SQL queries’ and you will find out that SQL queries have great potential, but can be very difficult and quite extensive. The SQL queries that we are going to use in this training are small and easy to use.
Before we start with different options, we need to understand what a query is and how you should read this. A general query will look like this:
SELECT * FROM assignment_4_data_sample_join WHERE manager = 'David Smit'
First part: the SELECT query
SELECT * FROM assignment_4_data_sample_join
This part means that we are going to select every column (*) from a dataset. If you want to view a certain column you can add that here. So if you wanted to only select the postal code column with the manager column you would write
SELECT postalcode, manager FROM assignment_4_data_sample_join
Second part: the WHERE query
WHERE manager = 'David Smit'
This part explains a certain condition that goes with the query. In this case the outcome would be only the rows where the manager value is equal to David Smit.
With a query you can get different kinds of information from your data. The first query will let you count how many rows are in your data set. The query would look like this:
SELECT COUNT (*) FROM assignment_4_data_sample_join
When you want to count something with a certain condition, you can add a WHERE clause to the query mentioned above. If you would like to count the number of rows of the whole dataset. This query will do. When you want to count the total number of rows where the manager value is ‘David Smit’, you need to add the WHERE clause mentioned earlier. In that case, your query will look like this:
SELECT COUNT (*) FROM assignment_4_data_sample_join WHERE manager = 'David Smit'
Looking for more SQL examples?
We have an extensive Help Center article that explains some of the most used SQL queries. In this article you can find more information about some of the following SQL queries and operators: