SQL Zero to Hero

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

What is the purpose of the GROUP BY clause in SQL?

  • To sort the results in a specific order.
  • To filter records based on a specific condition.
  • To combine rows that have the same values in specified columns. (correct)
  • To create an alias for a table.

Which SQL clause is used to restrict the results returned after grouping data?

  • WHERE
  • DISTINCT
  • ORDER BY
  • HAVING (correct)

What does the INNER JOIN keyword do in SQL?

  • Selects only those records that have matching values in both tables. (correct)
  • Selects unique records from the first table only.
  • Selects records from both tables that do not match.
  • Selects all records from the left table regardless of matches.

Which function would you use to find the highest value in a column?

<p>MAX() (A)</p> Signup and view all the answers

When using the ORDER BY clause, what does the 'ASC' keyword signify?

<p>Sorting results in ascending order. (C)</p> Signup and view all the answers

Which SQL statement retrieves values from a column only if they match a specified pattern?

<p>WHERE Column LIKE Pattern (C)</p> Signup and view all the answers

What is the purpose of the SUM() function in SQL?

<p>To find the cumulative total of a numeric column. (C)</p> Signup and view all the answers

What does the LEFT JOIN keyword accomplish in SQL?

<p>Retrieves all records from the left table and matched records from the right table. (C)</p> Signup and view all the answers

Flashcards

SQL Alias

A new name given to a table or column in a SQL query.

SQL GROUP BY

Groups rows with the same values in one or more columns.

SQL ORDER BY

Sorts query results in ascending or descending order.

SQL INNER JOIN

Selects rows from two tables where the join condition is true.

Signup and view all the flashcards

SQL AVG()

Calculates the average of values in a column.

Signup and view all the flashcards

SQL WHERE clause LIKE

Filters rows based on a pattern matching.

Signup and view all the flashcards

SQL WHERE clause IN

Filters rows where a column's value is present in a list.

Signup and view all the flashcards

SQL WHERE clause BETWEEN

Filters rows within a given range.

Signup and view all the flashcards

Study Notes

SQL Zero to Hero

  • ALIAS (AS): An alias is created using the "AS" keyword. Example: SELECT column_name AS alias_name FROM table_name;

GROUP BY

  • Group By Column: Groups rows with the same values in the specified column(s). Example: SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s);

HAVING

  • Having: Filters groups of data after grouping. Example: SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);

ORDER BY

  • ORDER BY (ASC) or ORDER BY DESC: Sorts data in ascending (ASC) or descending (DESC) order based on the specified column(s). Example: SELECT column1, column2 FROM table_name ORDER BY column1 ASC, column2 DESC;

JOINS

  • INNER JOIN: Selects rows from two or more tables that have matching values in the specified columns. Example: SELECT column_name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;

  • LEFT JOIN: Returns all rows from the left table (table1) and the matching rows from the right table (table2). If there's no match in the right table, it returns NULL for the right table's columns. Example: SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;

  • RIGHT JOIN: Similar to LEFT JOIN, but returns all rows from the right table and the matching rows from the left table. Example: SELECT column_name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;

  • FULL JOIN: Returns all rows from both tables. If there's no match in either table, it returns NULL for the columns from the other table. Example: SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name WHERE condition;

FUNCTIONS

  • AVG(): Calculates the average of values in a column. Example: SELECT AVG(column_name) FROM table_name WHERE condition;

  • SUM(): Calculates the sum of values in a column. Example: SELECT SUM(column_name) FROM table_name WHERE condition;

  • COUNT(): Counts the number of rows or values in a column. Example: SELECT COUNT(*) FROM table_name; or SELECT COUNT(column_name) FROM table_name;

  • MIN(): Returns the minimum value in a column. Example: SELECT MIN(column_name) FROM table_name WHERE condition;

  • MAX(): Returns the maximum value in a column. Example: SELECT MAX(column_name) FROM table_name WHERE condition;

WHERE

  • LIKE: Matches patterns in a column. Example: SELECT column1, column2 FROM table_name WHERE column1 LIKE 'pattern%';

  • IN: Matches values in a list. Example: SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);

  • BETWEEN: Matches values within a range. Example: SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;

  • ANY: Matches values that satisfy a subquery. Example: SELECT column_name(s) FROM table_name WHERE column_name operator ANY (SELECT column_name FROM table_name);

  • EXISTS: Checks if a subquery returns any rows. Example: SELECT column_name(s) FROM table_name WHERE EXISTS (SELECT 1 FROM table_name WHERE condition);

  • ALL: Matches values that satisfy a condition for all rows in a subquery Example: SELECT column_name FROM table_name WHERE column_name operator ALL (SELECT column_name FROM table_name);

  • AND, OR, NOT: Combine conditions. Example: SELECT column_name FROM table_name WHERE condition1 AND condition2 OR condition3;

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

SQL Zero to Hero PDF

More Like This

Database Design and SQL Fundamentals
12 questions
DBMS Fundamentals Quiz
12 questions

DBMS Fundamentals Quiz

SatisfyingChimera avatar
SatisfyingChimera
Fundamentals of Databases: Non-Table Objects
24 questions
Database Fundamentals and Queries
13 questions
Use Quizgecko on...
Browser
Browser