Top 10 Advanced SQL Queries for Beginners

Tejashree Salvi
2 min readJan 31, 2023

--

Here are SQL queries along with examples:

  1. UNION: combines the result set of two or more SELECT statements into a single result set. Example:
SELECT name FROM customers
UNION
SELECT name FROM suppliers;

2. INNER JOIN: combines only the matching rows from both tables into a single result set.

SELECT customers.name, orders.order_date
FROM customers
INNER JOIN orders
ON customers.id = orders.customer_id;

3. LEFT JOIN: combines all the rows from the left table and the matching rows from the right table into a single result set.

SELECT customers.name, orders.order_date
FROM customers
LEFT JOIN orders
ON customers.id = orders.customer_id;

4. RIGHT JOIN: combines all the rows from the right table and the matching rows from the left table into a single result set.

SELECT customers.name, orders.order_date
FROM customers
RIGHT JOIN orders
ON customers.id = orders.customer_id;

5. FULL OUTER JOIN: combines all the rows from both tables into a single result set, including non-matching rows.

SELECT customers.name, orders.order_date
FROM customers
FULL OUTER JOIN orders
ON customers.id = orders.customer_id;

6. SUBQUERY: a query within a query to extract data to use in the main query.

SELECT name, order_date
FROM orders
WHERE customer_id = (
SELECT id
FROM customers
WHERE name = 'Tony Stark'
);

7. COUNT(): returns the number of rows in a result set.

SELECT COUNT(*)
FROM customers;

8. SUM(): returns the sum of values in a result set.

SELECT SUM(price)
FROM orders;

9. AVG(): returns the average of values in a result set.

SELECT AVG(price)
FROM orders;

10. MAX(): returns the maximum value in a result set.

SELECT MAX(price)
FROM orders;

These are just a few of the many advanced MySQL queries that are available. The specific queries used in a particular situation will depend on the needs of the application and the structure of the data being stored in the database.

Hope this helps!

If you enjoyed reading this article, please take a moment to give it some claps and share it with others. 👏

--

--

Tejashree Salvi
Tejashree Salvi

Written by Tejashree Salvi

Learning DevOps, Blogging, Programming

Responses (1)