Public Deck

SQL Mastery - 40 Essential Queries

Master SQL from basics to advanced with 40 practical query examples covering JOINs, aggregations, subqueries, and optimization.

AnyFlashcards40 cards

Preview

Front

How do you sort the results of a query by 'hire_date' in descending order?

Back

ORDER BY hire_date DESC Use ASC for ascending (default) and DESC for descending order.

Front

Write a query to select all columns from a table named 'employees'.

Back

SELECT * FROM employees; The asterisk () is a wildcard used to retrieve every column in the table.*

Front

Write a query to select only the 'first_name' and 'last_name' from 'employees'.

Back

SELECT first_name, last_name FROM employees; Specifying columns reduces data transfer and improves performance.

Front

How do you retrieve only unique values from a column named 'department'?

Back

SELECT DISTINCT department FROM employees; The DISTINCT keyword removes duplicate rows from the result set.

Front

Write a query to find employees with a salary greater than 50,000.

Back

SELECT * FROM employees WHERE salary > 50000; The WHERE clause filters records based on a specified condition.

Front

Write a query to find employees whose names start with 'J'.

Back

SELECT * FROM employees WHERE first_name LIKE 'J%'; The % wildcard matches any sequence of characters.

Front

Write a query to return only the first 5 rows of a result set.

Back

SELECT * FROM employees LIMIT 5; LIMIT restricts the number of records returned (syntax may vary by DB, e.g., TOP in SQL Server).

Front

How do you rename a column in the output of a SELECT statement?

Back

SELECT first_name AS fname FROM employees; The AS keyword creates an alias for a column or table.

Front

What does an INNER JOIN do?

Back

Returns records with matching values in both tables. It excludes rows that do not have a corresponding match in the joined table.

Front

What is the result of a LEFT JOIN?

Back

All records from the left table and matched records from the right table. Unmatched rows from the right table will contain NULL values.

+ 30 more cards

Related Flashcard Decks

Ready to study?

Sign up for free to copy this deck and start learning with spaced repetition.

Get started for free