{"id":107432,"date":"2025-05-14T15:58:00","date_gmt":"2025-05-14T10:28:00","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/sql-queries-with-examples\/"},"modified":"2025-10-17T17:00:34","modified_gmt":"2025-10-17T11:30:34","slug":"sql-queries-with-examples","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/sql-queries-with-examples\/","title":{"rendered":"27 SQL Query Examples to Practice Data Analysis"},"content":{"rendered":"\n<p>This guide provides 27 practical SQL query examples to help you master data analysis. We will start from basic data retrieval with <strong>SELECT<\/strong> to advanced analytical techniques using <strong>window functions<\/strong> and <strong>CTEs<\/strong>.<\/p>\n\n\n\n<p>This article focuses specifically on <strong>querying<\/strong> - the method of asking questions to get answers from your data. If you need a foundational overview of all SQL command types (like DDL for creating tables or DCL for permissions) first, see our complete guide to <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\">SQL Commands<\/a>.<\/p>\n\n\n\n<p>We'll use two simple tables for most examples: <strong>employees<\/strong> and <strong>departments<\/strong>.<\/p>\n\n\n\n<p><strong>employees table:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>employee_id<\/th><th>first_name<\/th><th>last_name<\/th><th>salary<\/th><th>department_id<\/th><th>hire_date<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>John<\/td><td>Smith<\/td><td>60000<\/td><td>1<\/td><td>2022-01-15<\/td><\/tr><tr><td>2<\/td><td>Jane<\/td><td>Doe<\/td><td>75000<\/td><td>1<\/td><td>2021-03-20<\/td><\/tr><tr><td>3<\/td><td>Peter<\/td><td>Jones<\/td><td>90000<\/td><td>2<\/td><td>2020-05-10<\/td><\/tr><tr><td>4<\/td><td>Mary<\/td><td>Williams<\/td><td>80000<\/td><td>2<\/td><td>2021-08-01<\/td><\/tr><tr><td>5<\/td><td>David<\/td><td>Brown<\/td><td>65000<\/td><td>3<\/td><td>2023-01-05<\/td><\/tr><tr><td>6<\/td><td>null<\/td><td>Davis<\/td><td>55000<\/td><td>3<\/td><td>2023-02-12<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>departments table:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>department_id<\/th><th>department_name<\/th><\/tr><\/thead><tbody><tr><td>1<\/td><td>Engineering<\/td><\/tr><tr><td>2<\/td><td>Sales<\/td><\/tr><tr><td>3<\/td><td>Marketing<\/td><\/tr><tr><td>4<\/td><td>HR<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-title-link\">SQL Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master SQL and Database management with this SQL course: Practical training with guided projects, AI support, and expert instructors.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>7 Hrs<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>2 Projects<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/practical-sql-training\" class=\"courses-cta-button\">\n                Take SQL Course Now\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"the-basics-data-retrieval\">The Basics: Data Retrieval<\/h2>\n\n\n\n<p>These are the basic queries you'll use every single day. Don't just learn them, know them.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"1-select\">1. SELECT *<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Selects all columns from a table.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> This query returns every single row and column from the <code>employees<\/code> table. Use it to get a quick look at your data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"2-select-specific-columns\">2. SELECT [specific columns]<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Selects only the columns you specify. More efficient than <code>SELECT *<\/code>.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT first_name, last_name, salary FROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Returns only the <code>first_name<\/code>, <code>last_name<\/code>, and <code>salary<\/code> for all employees.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"3-where\">3. WHERE<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Filters records based on a condition.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM employees WHERE salary &gt; 70000;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> This shows all information for employees earning more than 70,000.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"4-and-or\">4. AND \/ OR<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Combines multiple conditions in a <code>WHERE<\/code> clause.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM employees WHERE salary &gt; 70000 AND department_id = 2;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Retrieves employees who are in department 2 <strong>AND<\/strong> have a salary over 70,000.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"5-order-by\">5. ORDER BY<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Sorts the results. The default is ascending (<code>ASC<\/code>).<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT first_name, salary FROM employees ORDER BY salary DESC;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Displays employee first names and salaries, sorted from highest salary to lowest.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"6-limit\">6. LIMIT<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Restricts the number of rows returned.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM employees ORDER BY hire_date DESC LIMIT 3;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Gets the top 3 most recently hired employees.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"7-distinct\">7. DISTINCT<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Returns only unique values.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT DISTINCT department_id FROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Shows a list of unique <code>department_ids<\/code> that have employees, which would be 1, 2, and 3.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"8-like\">8. LIKE<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Used in a <code>WHERE<\/code> clause to search for a specific pattern in a column.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT first_name, last_name FROM employees WHERE last_name LIKE &#039;J%&#039;;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Finds all employees whose last name starts with 'J'. The <code>%<\/code> is a wildcard.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"9-is-null-is-not-null\">9. IS NULL \/ IS NOT NULL<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Checks for empty values.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT * FROM employees WHERE first_name IS NULL;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Retrieves rows where the <code>first_name<\/code> has not been entered, like employee_id 6.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"medium-level-queries-joins-and-aggregations\">Medium Level Queries: Joins and Aggregations<\/h2>\n\n\n\n<p>This is where you start combining and analyzing data. Master these, and you're hireable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"10-inner-join\">10. INNER JOIN<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Combines rows from two or more tables based on a related column. Returns only matching rows.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT e.first_name, e.last_name, d.department_name\nFROM employees e\nINNER JOIN departments d ON e.department_id = d.department_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> This query lists each employee and their corresponding department name. The HR department won't show up because no employee is assigned to it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"11-left-join\">11. LEFT JOIN<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Returns all records from the left table (<code>employees<\/code>), and the matched records from the right table (<code>departments<\/code>).<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT e.first_name, d.department_name\nFROM employees e\nLEFT JOIN departments d ON e.department_id = d.department_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Shows all employees and their department. If an employee had a <code>department_id<\/code> that didn't exist in <code>departments<\/code>, their <code>department_name<\/code> would be <code>NULL<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"12-right-join\">12. RIGHT JOIN<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Returns all records from the right table (<code>departments<\/code>), and the matched records from the left.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT e.first_name, d.department_name\nFROM employees e\nRIGHT JOIN departments d ON e.department_id = d.department_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> This will list all departments and the employees in them. The HR department will appear with a <code>NULL first_name<\/code> because it has no employees.<\/p>\n\n\n\n<p>Also Read: <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-joins\/\">SQL Joins - Inner, Left, Right &amp; Full Join<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"13-count\">13. COUNT()<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> An aggregate function that counts the number of rows.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT COUNT(*) FROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Returns the total number of employees, which is 6.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"14-sum\">14. SUM()<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Calculates the total sum of a numeric column.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT SUM(salary) FROM employees WHERE department_id = 1;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Calculates the total salary for all employees in the Engineering department (60000 + 75000).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"15-avg\">15. AVG()<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Calculates the average value of a numeric column.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT AVG(salary) FROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Gives the average salary of all employees.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"16-group-by\">16. GROUP BY<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Groups rows that have the same values into summary rows. Often used with aggregate functions.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT department_id, COUNT(employee_id) as num_employees\nFROM employees\nGROUP BY department_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Shows how many employees are in each department.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"17-having\">17. HAVING<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Filters groups based on a condition after <code>GROUP BY<\/code>. <code>WHERE<\/code> filters rows before grouping.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT d.department_name, AVG(e.salary) as avg_salary\nFROM employees e\nJOIN departments d ON e.department_id = d.department_id\nGROUP BY d.department_name\nHAVING AVG(e.salary) &gt; 70000;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> This query shows departments where the average salary is greater than 70,000.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"18-case\">18. CASE<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Adds if-then-else logic to your queries.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT first_name, salary,\n    CASE\n        WHEN salary &gt; 85000 THEN &#039;High Earner&#039;\n        WHEN salary &gt; 70000 THEN &#039;Mid Earner&#039;\n        ELSE &#039;Standard Earner&#039;\n    END as salary_bracket\nFROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Creates a new column <code>salary_bracket<\/code> and categorizes each employee based on their salary.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"19-subquery-or-inner-query\">19. Subquery (or Inner Query)<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> A query nested inside another query.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT first_name, last_name\nFROM employees\nWHERE department_id IN (SELECT department_id FROM departments WHERE department_name = &#039;Sales&#039;);\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Gets the names of all employees who work in the 'Sales' department. The inner query finds the <code>department_id<\/code> for Sales first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"advanced-sql-queries-window-functions-and-ctes\">Advanced SQL Queries: Window Functions and CTEs<\/h2>\n\n\n\n<p>If you can use these fluently, you're not a junior anymore. These are for complex analysis.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"20-common-table-expression-cte\">20. Common Table Expression (CTE)<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Creates a temporary, named result set that you can reference within your main query.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nWITH HighSalaries AS (\n    SELECT employee_id, first_name, salary\n    FROM employees\n    WHERE salary &gt; 75000\n)\nSELECT * FROM HighSalaries;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> The <code>WITH<\/code> clause defines a temporary table <code>HighSalaries<\/code>, which is then queried. It's cleaner than a subquery for complex logic.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"21-row_number\">21. ROW_NUMBER()<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> A window function that assigns a unique number to each row within a partition.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT\n    first_name,\n    department_name,\n    salary,\n    ROW_NUMBER() OVER(PARTITION BY department_name ORDER BY salary DESC) as rank_in_dept\nFROM employees e\nJOIN departments d ON e.department_id = d.department_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> This ranks employees within each department based on salary. The highest salary in each department gets rank 1.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"22-rank-dense_rank\">22. RANK() &amp; DENSE_RANK()<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Ranks rows within a partition. <code>RANK()<\/code> will skip ranks after a tie (e.g., 1, 2, 2, 4), while <code>DENSE_RANK()<\/code> will not (e.g., 1, 2, 2, 3).<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT\n    first_name,\n    salary,\n    RANK() OVER(ORDER BY salary DESC) as salary_rank\nFROM employees;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Assigns a rank to each employee based on their overall salary.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"23-lag-lead\">23. LAG() &amp; LEAD()<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Accesses data from a previous row (<code>LAG<\/code>) or a subsequent row (<code>LEAD<\/code>) without a self-join.<\/p>\n\n\n\n<p><strong>Example:<\/strong> (Assume a table <code>sales<\/code> with <code>sale_date<\/code> and <code>sale_amount<\/code>)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT\n    sale_date,\n    sale_amount,\n    LAG(sale_amount, 1, 0) OVER(ORDER BY sale_date) as previous_day_sales\nFROM sales;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Shows each day's sales next to the previous day's sales, making day-over-day comparisons easy.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"24-moving-average\">24. Moving Average<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Calculates averages over a specific window of rows.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT\n    sale_date,\n    sale_amount,\n    AVG(sale_amount) OVER(ORDER BY sale_date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) as three_day_moving_avg\nFROM sales;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> For each day, it calculates the average sales of that day and the two preceding days.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"25-pivot-conditional-aggregation\">25. PIVOT (Conditional Aggregation)<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Rotates a table by turning unique values from one column into multiple columns.<\/p>\n\n\n\n<p><strong>Example:<\/strong> (using <code>CASE<\/code> for general compatibility)<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT\n    department_id,\n    COUNT(CASE WHEN salary &gt; 70000 THEN 1 END) as high_earners,\n    COUNT(CASE WHEN salary &amp;lt;= 70000 THEN 1 END) as standard_earners\nFROM employees\nGROUP BY department_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Creates a report showing the count of high vs. standard earners for each department.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"26-self-join\">26. Self Join<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Joining a table to itself to compare rows within the same table.<\/p>\n\n\n\n<p><strong>Example:<\/strong> Find employees who were hired on the same day.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT e1.first_name, e1.last_name, e2.first_name, e2.last_name, e1.hire_date\nFROM employees e1\nJOIN employees e2 ON e1.hire_date = e2.hire_date AND e1.employee_id &gt; e2.employee_id;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Compares every employee record (<code>e1<\/code>) with every other employee record (<code>e2<\/code>) to find matches on <code>hire_date<\/code>. <code>e1.employee_id &gt; e2.employee_id<\/code> prevents duplicates and self-matching.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"27-union-union-all\">27. UNION \/ UNION ALL<\/h3>\n\n\n\n<p><strong>What it does:<\/strong> Combines the result set of two or more <code>SELECT<\/code> statements. <code>UNION<\/code> removes duplicates, <code>UNION ALL<\/code> includes all records.<\/p>\n\n\n\n<p><strong>Example:<\/strong><\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nSELECT first_name, last_name FROM employees WHERE department_id = 1\nUNION\nSELECT first_name, last_name FROM employees WHERE department_id = 2;\n<\/pre><\/div>\n\n\n<p><strong>Explanation:<\/strong> Creates a single list of all employees from departments 1 and 2.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"best-practices-for-writing-effective-queries\">Best Practices for Writing Effective Queries<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Write Clearly:<\/strong> Use short names (aliases) for tables in joins (like <code>e<\/code> for employees). Make your code easy to read by using spaces and putting parts on new lines. Add comments (<code>--<\/code> at the start of a line) to explain tricky parts.<\/li>\n\n\n\n<li><strong>Make Them Fast:<\/strong> Use <code>CREATE INDEX<\/code> on columns you often filter or join on. Only select the columns you actually need; don't just use <code>SELECT *<\/code>. Look at the \"query plan\" to see how the database runs your query and where it's slow.<\/li>\n\n\n\n<li><strong>Avoid Problems:<\/strong> Remember that <code>NULL<\/code> is tricky; use <code>IS NULL<\/code> or <code>IS NOT NULL<\/code> to check for it. Test your queries on a small amount of data first. Double-check your <code>JOIN<\/code> conditions to make sure you are linking tables correctly.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>SQL queries are powerful tools. They let you get, analyze, and understand the data in your databases.<\/p>\n\n\n\n<p>We've looked at many types of queries, from simple selections to complex joins and aggregations.<\/p>\n\n\n\n<p>What should you do next? Practice! Find some sample databases online (like AdventureWorks or Chinook) and try running these queries yourself.<\/p>\n\n\n\n<p>You can use this <a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-editor-tool\/\">Online SQL Compiler Tool<\/a> to easily test queries.<\/p>\n\n\n\n<p>Keep trying and exploring. The more you write and run queries, the better you will become at extracting insights from your data!<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"other-sql-resources\">Other SQL Resources:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-quiz\/\">SQL Quiz<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/hands-on-sql-projects\/\">SQL Projects<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-exercises\/\">SQL Exercises<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-interview-questions\/\">SQL Interview Questions and Answers<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/what-does-an-sql-developer-do\/\">How to Become an SQL Developer<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.<\/p>\n","protected":false},"author":41,"featured_media":112813,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36844],"content_type":[36252],"class_list":["post-107432","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-sql","content_type-tutorials"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>27 SQL Query Examples to Practice Data Analysis<\/title>\n<meta name=\"description\" content=\"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"27 SQL Query Examples to Practice Data Analysis\" \/>\n<meta property=\"og:description\" content=\"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-14T10:28:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-10-17T11:30:34+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1408\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-queries-with-examples\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"27 SQL Query Examples to Practice Data Analysis\",\"datePublished\":\"2025-05-14T10:28:00+00:00\",\"dateModified\":\"2025-10-17T11:30:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-queries-with-examples\\\/\"},\"wordCount\":1304,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/sql-queries-data-analysis.webp\",\"keywords\":[\"sql\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-queries-with-examples\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\",\"name\":\"27 SQL Query Examples to Practice Data Analysis\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/sql-queries-data-analysis.webp\",\"datePublished\":\"2025-05-14T10:28:00+00:00\",\"dateModified\":\"2025-10-17T11:30:34+00:00\",\"description\":\"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/sql-queries-data-analysis.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/sql-queries-data-analysis.webp\",\"width\":1408,\"height\":768,\"caption\":\"SQL queries to master data analysis\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/sql-commands\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"27 SQL Query Examples to Practice Data Analysis\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"27 SQL Query Examples to Practice Data Analysis","description":"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","og_locale":"en_US","og_type":"article","og_title":"27 SQL Query Examples to Practice Data Analysis","og_description":"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.","og_url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2025-05-14T10:28:00+00:00","article_modified_time":"2025-10-17T11:30:34+00:00","og_image":[{"width":1408,"height":768,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp","type":"image\/webp"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-queries-with-examples\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"27 SQL Query Examples to Practice Data Analysis","datePublished":"2025-05-14T10:28:00+00:00","dateModified":"2025-10-17T11:30:34+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-queries-with-examples\/"},"wordCount":1304,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp","keywords":["sql"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-queries-with-examples\/","url":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/","name":"27 SQL Query Examples to Practice Data Analysis","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp","datePublished":"2025-05-14T10:28:00+00:00","dateModified":"2025-10-17T11:30:34+00:00","description":"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp","width":1408,"height":768,"caption":"SQL queries to master data analysis"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/sql-commands\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"27 SQL Query Examples to Practice Data Analysis"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp",1408,768,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-300x164.webp",300,164,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-768x419.webp",768,419,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-1024x559.webp",1024,559,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp",1408,768,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis.webp",1408,768,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-640x768.webp",640,768,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2025\/05\/sql-queries-data-analysis-150x82.webp",150,82,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"Explore 30+ query examples for data retrieval, joins, aggregation, updates, and more.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/107432","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=107432"}],"version-history":[{"count":45,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/107432\/revisions"}],"predecessor-version":[{"id":113167,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/107432\/revisions\/113167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/112813"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=107432"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=107432"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=107432"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=107432"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}