Back to articles list Articles Cookbook
8 minutes read

SQL Beginners: Questions to Ask Before Writing a Query

SQL is known for its easy-to-follow syntax that even beginners can understand pretty quickly. Still, to write your own SQL queries, you need to know the basics. Let’s explore what things need to be considered before writing a SQL query.

If you are looking for a career in data analysis or just want to work effectively and independently with data in any analytical position, you’ll need to master SQL. Luckily, this programming language is beginner-friendly and can be learned just in a few months with the right learning sources.

I recommend our SQL from A to Z learning track for anyone who wants to learn the necessary tools to work efficiently with any type of data. This track includes 7 interactive courses and hundreds of coding challenges; it covers SQL basics, standard SQL functions, SQL reports, and more advanced topics like window functions and recursive queries. Join the 200K+ users enrolled in this track and power up your daily work!

To give you a better understanding of the things you’ll know after mastering SQL, let’s start with the basics and discuss what SQL is and what you need to know to write SQL queries like a pro.

What Is SQL?

SQL, or Structured Query Language, is a programming language used to interact with databases. You use SQL to store, manipulate, and retrieve data from relational databases.

If relational databases sound confusing, remember that they are just a set of tables with columns and rows. They have data items across different tables that have pre-defined relationships. For example, a customer ID from the orders table can lead you to all the information you store on this customer in the customers table.

Relational databases are a very common way for businesses to store information, whether it is a small flower shop or a huge international company like Uber. And SQL is an industry standard for communicating with these databases.

As a powerful tool for retrieving information from relational databases, SQL allows you to combine information from multiple tables, apply complex filter conditions, analyze the retrieved data, and report the results. However, SQL's capabilities go far beyond the mere retrieval of information, as it can be also used for creating new databases and keeping them up to date.

SQL dates back to the 1970s, but it still remains one of the key programming languages for data management and analysis. Today, a wide range of specialists – including software developers, testers, business analysts, data engineers, and data scientists – benefit from knowing SQL. 

Learn more about SQL’s history and applications and you’ll see that learning SQL will definitely pay off.

What Is a SQL query?

When we use SQL to communicate with relational databases, we do so through SQL queries. So, let’s explore what a SQL query is and how it works.

A SQL query is a command used to get data out of a database. Essentially, it is a question that you ask a database. If your question is “What are the names of the sales representatives who started in 2017 or earlier?”, your SQL query can be:

SELECT first_name, last_name
FROM sales_rep
WHERE employment_year <= 2017 AND department = ‘Sales’;

Note that the query is human-readable and easy to understand, even for SQL beginners.

The SQL query above is pretty basic. You’ll be dealing with additional complexity when combining information from multiple tables, grouping data items, sorting your data in a specific order, doing basic calculations, etc. You can find detailed examples of basic and advanced SQL queries elsewhere in this blog.

Before you’re ready to write a SQL query, you’ll need to consider several essential things. Let’s see what they are.

7 Questions to Answer Before Writing a SQL Query

The list below is not exhaustive – the issues you’ll need to consider will usually depend on the problem you want to address. So, here are the most common considerations that a SQL beginner should think about before writing a query.

1. What’s the purpose of this SQL query?

Before starting a SQL query, you should clearly understand what exactly you want to get. Many query errors come from not truly grasping the problem to be solved. SQL beginners may find it useful to visualize or even draw the expected output table before writing the query. This way, you’ll have a better idea of what columns and rows from what tables you want to see in the result.

2. Which SQL dialect should I use?

While SQL is a standard language for interacting with relational databases, it’s important to know that it has its dialects. There are several popular relational database management systems (RDBMs) that use slightly different SQL dialects. Dialects in SQL are similar to the dialects in spoken languages – most of the words are the same, but some words are unique to certain regions (or database management systems).

The most popular databases in 2022 are MySQL, PostgreSQL, SQLite, MongoDB, Microsoft SQL Server, and Oracle. The syntax across these databases doesn’t differ dramatically, but each one has a few of its own special rules. Thus, you’ll often have SQL queries that work with one database but not another.

So, before writing a SQL query, you need to be aware of a database management system deployed in your company – and hence the SQL dialect to be used.

3. Do I know the syntax?

Is your SQL knowledge sufficient for writing this particular SQL query? For example, if you realize that you need to filter data items based on a calculated average and you don’t know how to do basic calculations in SQL, you will not be able to write an effective query. In this case, I would recommend taking the SQL Basics course to learn how to retrieve data from an SQL database and build simple reports.

4. Do I know the names of all tables and columns?

To write a working SQL query, you need to know your database well. This  includes all the tables, what kind of information is stored in each table, and how the tables are interrelated.

If you’re working with large databases, it would be difficult to remember all the names of all tables and columns. However, a typo or missing underscore in a table or column name will result in unexpected errors and frustration. So, if it’s not feasible to remember all the names, make sure you review a database schema before writing your SQL query. You need to ensure that all the names used in the query are correct.

5. Will I neeed to extract data from more than one table?

The problem that you want to address with a SQL query may require extracting information from several related tables (e.g. customers and orders or sales representatives and orders). That problem can be easily solved with SQL, but you’ll need to master SQL joins. Learn how to join tables in SQL with our interactive SQL JOINs course.

6. Do I know SQL’s order of operations?

Let’s say you know how to extract information from one or more tables, group data, add complex filtering conditions, and sort data. However, to get the output as expected, it’s also critical to follow the SQL order of operations, which requires putting SQL clauses in a certain order. If you fail to construct your query properly, its output will not be as expected – or you may just get an error and no output at all! So, before writing a SQL query, make sure you know the correct order of operations.

7. Can I export the output data?

You’ll often need to export the output of your query to a text file or spreadsheet for further analysis and reporting. You can do this using certain SQL clauses. It would be good to know these clauses and how to use them before extracting the data from a database; this way, you can be sure you’ll be able to use the output as intended.

Let’s Learn SQL!

Companies of all sizes store their data in relational databases; SQL is an industry standard for interacting with these databases. Thus, it’s hard to overestimate how important knowledge of SQL is for the successful careers of data analysts, data scientists, and other professionals who work with data.

If you want to build a successful career in a data-driven organization, it’s time to learn SQL! Here are a few LearnSQL.com courses that can help you in your learning journey:

SQL Basics

For absolute beginners, I recommend the SQL Basics course. Its 129 interactive exercises cover fundamental SQL topics, such as retrieving data from a database, combining information from multiple tables, aggregating and grouping data, performing simple computations on data, etc.

The course is designed for beginners, but it is also useful for those who have basic SQL knowledge and want to review and consolidate what they know.

Things To Consider Before Writing a SQL Query

On LearnSQL.com, the SQL Basics course is available for standard SQL as well as for the MS SQL Server, PostgreSQL, and MySQL dialects.

SQL from A to Z

If you are ready to go beyond basics, consider taking the SQL from A to Z learning track I described at the beginning of this article.

Things To Consider Before Writing a SQL Query

It covers both basic and advanced features of SQL, allowing you to master this tool even with no prior exposure to SQL. This learning track is available in standard SQL and the MS SQL Server, PostgreSQL, and MySQL dialects.

Follow these five tips for learning SQL for beginners and you’ll master this powerful programming language in no time.

Bonus: Here are the best SQL books and top resources for finding the perfect SQL job.

Happy learning!