DEV Community

AiinfoxAcademy
AiinfoxAcademy

Posted on

SQL for Data Science Beginners: Top Queries You Should Practice First

Data science isn't only about Python, machine learning, and statistics. A good percentage of real-world data work begins with discovering, filtering, and sorting information, which is stored inside databases. That's where SQL comes into play.
SQL stands for Structured Query Language, and it is one of the most popular languages of interaction with relational databases. For aspiring data scientists, knowing only a handful of essential SQL queries can help significantly when working with business data, cleaning datasets, and querying data.
You won't need to learn all the commands straight away. Instead, focus on the queries you are likely to use while working on actual data projects.

  1. Practice with SELECT The SELECT command is the basis of all SQL, and you can use it to select the specific columns you want to use from a table. For example: SELECT name, age, city FROM customers; This query will return only the columns of the customer table you're interested in, skipping all the rest. Beginner data scientists should practice selecting individual columns as opposed to always writing SELECT *, as understanding the structure of tables is helpful for your projects.
  2. Filter Data with WHERE Real datasets are huge, often containing thousands or even millions of records. In most cases, you won't need all of them at the same time. The WHERE command helps you filter records by specified criteria: SELECT * FROM customers WHERE city = 'Chandigarh'; You can also use comparison operators >, <, >=, and <=. For example: SELECT * FROM orders WHERE amount > 5000; It's useful to practice filtering because data analysts often want to extract some groups before doing further analysis.
  3. Sort Your Results with ORDER BY After you have filtered the data, you may want to sort it in a certain order. The ORDER BY command sorts the data either in ascending or descending order: SELECT product_name, price FROM products ORDER BY price DESC; This way, you can see the most expensive products in your dataset. For data science beginners, sorting helps when you want to analyse trends, common values, or lowest/highest values.
  4. Use Aggregate Functions to Summarise Data Analysing data often means summarising the data instead of reviewing every row. Some frequently used aggregate functions include: COUNT () for counting records SUM () for totalling AVG () for averaging MIN () for the lowest value MAX () for the highest value For example: SELECT AVG (salary) FROM employees; These functions are essential because many business questions start with simple aggregations.
  5. Group Data with GROUP BY The GROUP BY command helps when you want similar summaries for different categories. For example: SELECT department, AVG (salary) FROM employees GROUP BY department; Instead of getting one overall average salary, you get the average for every department. This kind of query is typical in data science because analysts often compare performance across cities, product types, customer groups, or time frames.
  6. Get Comfortable with JOINs In practical scenarios, data is often stored in separate tables, where, for example, customer information is in one table, and their transactions are in another. In such cases, you need to be able to join different tables together. A basic INNER JOIN looks like this: SELECT customers. name, orders.amount FROM customers INNER JOIN orders ON customers.id = orders.customer_id; This way, you can connect related data tables. Beginner data scientists should learn to use INNER JOIN first, and then move to LEFT JOIN, RIGHT JOIN, and other types.
  7. Learn about HAVING with Grouped Data Similar to WHERE, but primarily used after grouping data, the HAVING command lets you extract only the groups you're interested in: For example: SELECT department, COUNT () FROM employees GROUP BY department HAVING COUNT () > 10; This returns only the departments with more than 10 employees. Knowing the difference between WHERE and HAVING takes you closer to writing more complex analytical queries. Improve Your Data Skills with Practice When it comes to learning SQL for data science, the best way is to work on real datasets instead of memorising commands. Use simple tables such as customers, sales, products, employees, or orders. Practice asking yourself questions like: Which products bring in the most sales? Which customers placed the most orders? What is the average transaction amount by city? Which department has the most employees? This way, you connect your SQL syntax to your analytical thinking. AiinfoxAcademy helps students who are upskilling for careers in data science, data analytics, AI, and machine learning to get a head start by strengthening their database fundamentals along with programming languages. You may find SQL looks too basic at first, but it is an essential element of every real-world data task. Master the core queries, and you will find data processing, reporting, and data science projects a lot easier.

Top comments (0)