SQL Commands and Grouping
8 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the correct SQL syntax to create an alias for a column?

  • SELECT Column_name AS 'alias_name' FROM table_name;
  • SELECT Column_name WITH alias_name FROM table_name;
  • SELECT alias_name FROM Column_name;
  • SELECT Column_name AS alias_name FROM table_name; (correct)

Which SQL clause is used to filter groups created by a GROUP BY statement?

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

What keyword is used to sort the result set in descending order?

  • ORDER BY DESCENDING
  • SORT BY DESC
  • ORDER BY DECREASING
  • ORDER BY DESC (correct)

Which type of JOIN returns all records from the left table and matched records from the right table?

<p>Left Join (D)</p> Signup and view all the answers

What does the AVG function in SQL compute?

<p>The average value of a column (A)</p> Signup and view all the answers

Which SQL statement correctly uses the LIKE operator?

<p>SELECT column_name FROM table_name WHERE column_name LIKE 'pattern'; (A)</p> Signup and view all the answers

What will the following SQL statement return? SELECT Column_name FROM table_name WHERE Column_name BETWEEN Value1 AND Value2;

<p>Records with Column_name within the range of Value1 and Value2, inclusive. (D)</p> Signup and view all the answers

Which of the following SQL statements is correctly structured to check for the existence of a record?

<p>SELECT EXISTS (SELECT Column_name FROM table_name WHERE Condition); (C)</p> Signup and view all the answers

Flashcards

SQL Alias

A shorter name for a column or table in a query, using the 'AS' keyword.

SQL GROUP BY

Groups rows with the same values in specified columns.

SQL HAVING

Filters grouped results based on conditions.

SQL ORDER BY

Sorts query results in ascending or descending order.

Signup and view all the flashcards

SQL INNER JOIN

Returns rows when values in specified columns are equal across multiple tables.

Signup and view all the flashcards

SQL AVG()

Calculates the average of values in a column.

Signup and view all the flashcards

SQL WHERE LIKE

Filters data based on patterns (using wildcards).

Signup and view all the flashcards

SQL WHERE IN

Filters data based on a list of values.

Signup and view all the flashcards

Study Notes

SQL Commands

  • ALIAS: Creates an alias for a column using the AS keyword.
    • Example: SELECT column_name AS alias_name FROM table_name;

SQL GROUP BY

  • GROUP BY: Groups rows that have the same values in specified columns.
    • Example: SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) ORDER BY column_name(s);

SQL HAVING

  • HAVING: Filters groups of rows based on a condition.
    • Example:SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s) HAVING condition ORDER BY column_name(s);

SQL ORDER BY

  • ORDER BY: Sorts the result set in ascending (ASC) or descending (DESC) order.
    • Example: SELECT column1, column2 FROM table_name ORDER BY column1 ASC, column2 DESC;

SQL JOINS

  • INNER JOIN: Returns rows where the values in specified columns match in both tables.

    • 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, and the matching rows from the right table.

    • Example: SELECT column_name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;
  • RIGHT JOIN: 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, combining matching rows and rows with no match in the other.

    • Example: SELECT column_name(s) FROM table1 FULL OUTER JOIN table2 ON table1.column_name = table2.column_name;

SQL FUNCTIONS

  • AVG(): Calculates the average of a numeric column.

    • Example: SELECT AVG(column_name) FROM table_name WHERE condition;
  • SUM(): Calculates the sum of a numeric 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;
    • Example: SELECT COUNT(column_name) FROM table_name;
  • MIN(): Finds the minimum value in a numeric column.

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

    • Example: SELECT MAX(column_name) FROM table_name WHERE condition;

SQL WHERE Clause

  • LIKE: Matches values based on a pattern.
    • Example: SELECT column1, column2 FROM table_name WHERE column1 LIKE '%abc%';
  • IN: Matches values within a specific set of values.
    • Example: SELECT column_name(s) FROM table_name WHERE column_name IN (value1, value2, ...);
  • BETWEEN: Matches values within a specified range.
    • Example: SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2;
  • ANY/SOME: Compares a value to any/some value in a subquery.
    • Example: SELECT column_name FROM table_name WHERE column_name > ANY (SELECT column_name FROM another_table);
  • EXISTS: Checks if a subquery returns any rows.
    • Example: SELECT column_name FROM table_name WHERE EXISTS (SELECT 1 FROM another_table WHERE condition);
  • AND, **OR, **NOT: Combines conditions using logical operators.

Boolean Operators

  • AND: Returns TRUE if both conditions are TRUE.
  • OR: Returns TRUE if at least one condition is TRUE.
  • NOT: Returns the opposite of the condition.

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

Description

Test your knowledge on SQL commands like ALIAS, GROUP BY, HAVING, and ORDER BY. This quiz will help you understand how to manipulate and retrieve data efficiently from databases using SQL. Perfect for students and professionals looking to sharpen their database skills.

More Like This

SQL Commands Overview
14 questions

SQL Commands Overview

ExquisitePalladium avatar
ExquisitePalladium
Advanced Database - Lecture 3
33 questions
Advanced Database Lecture 3
10 questions
Use Quizgecko on...
Browser
Browser