Which command is used to filter group results generated by the GROUP BY clause?
Answer(s): B
The HAVING clause is used in SQL to filter grouped results generated by the GROUP BY clause. Unlike WHERE, which filters individual rows before grouping, HAVING filters after aggregation has been performed.Example Usage:sqlSELECT Department, AVG(Salary) AS AvgSalaryFROM EmployeesGROUP BY DepartmentHAVING AVG(Salary) > 50000;This query first groups employees by Department, calculates the average salary per department, and then filters only those departments where the average salary is greater than 50,000.Why Other Options Are Incorrect:Option A (REPLACE) (Incorrect): Used for string substitution, not filtering.Option C (WITH) (Incorrect): Used in Common Table Expressions (CTEs), not for filtering.Option D (WHERE) (Incorrect): Used for row-level filtering before aggregation, but it cannot be used on aggregate functions like SUM() or AVG().Thus, HAVING is the correct answer for filtering after grouping.
SQL Aggregation and Grouping.
Which expression can be used to create a temporary name for a table?
Answer(s): C
An alias is used in SQL to give a temporary name to a table or column within a query. It makes queries more readable and helps in cases where a table needs to be referenced multiple times (e.g., in a self-join).Example Usage:sqlSELECT e.Name, d.DepartmentNameFROM Employees AS eJOIN Departments AS dON e.DeptID = d.ID;Here, Employees is aliased as e and Departments as d, making the query shorter and clearer.Why Other Options Are Incorrect:Option A (HAVING) (Incorrect): Used to filter grouped results, not create aliases.Option B (NEW) (Incorrect): Not a valid SQL keyword for aliasing.Option D (UNION) (Incorrect): Combines result sets but does not rename tables.Thus, the correct answer is ALIAS, which allows for temporary naming of tables or columns.
SQL Aliases and Temporary Naming.
Which type of join selects all the rows from both the left and right table, regardless of match?
Answer(s): A
A Full Join (FULL OUTER JOIN) selects all records from both tables, filling in NULL values where there is no match. This ensures that no data is lost from either table.Example Usage:sqlSELECT Employees.Name, Departments.DepartmentNameFROM EmployeesFULL OUTER JOIN Departments ON Employees.DeptID = Departments.ID;This query retrieves all employees and all departments, even if an employee has no assigned department or a department has no employees.Types of Joins:FULL OUTER JOIN (Correct Answer) Includes all rows from both tables, filling missing values with NULL.LEFT JOIN (Incorrect) Includes all rows from the left table and matching rows from the right table.RIGHT JOIN (Incorrect) Includes all rows from the right table and matching rows from the left table.CROSS JOIN (Incorrect) Produces a Cartesian product (each row from one table is combined with every row from another table).Thus, the correct answer is FULL JOIN, which ensures that all rows from both tables appear in the result.
SQL Join Types Explained.
Which function removes only the leading spaces from a string?
The LTRIM() function in SQL removes leading spaces (spaces at the beginning of a string) while keeping spaces at the end.Example Usage:sqlSELECT LTRIM(' Hello World') AS TrimmedText;Output:bash'Hello World'Why Other Options Are Incorrect:Option B (LEFT) (Incorrect): Used for extracting a portion of a string. Example:sqlSELECT LEFT('Hello World', 5); -- Output: 'Hello'Option C (TRIM) (Incorrect): Removes both leading and trailing spaces, not just leading ones.Example:sqlSELECT TRIM(' Hello World '); -- Output: 'Hello World'Option D (REPLACE) (Incorrect): Replaces occurrences of one substring with another but does not specifically remove spaces.Thus, the correct answer is LTRIM(), which removes only leading spaces.
SQL String Functions.
Which SQL command uses the correct syntax to add a new employee "John Doe" to the Employee table?
The correct syntax for inserting a new row into a table follows this structure:Standard SQL INSERT Syntax:sqlINSERT INTO TableName (Column1, Column2, ...)VALUES (Value1, Value2, ...);For this scenario:sqlINSERT INTO Employee (Name) VALUES ('John Doe');Why Other Options Are Incorrect:Option A (Incorrect): Uses incorrect syntax { ... }, which is not valid SQL syntax.Option C (Incorrect): Does not specify the column name, which causes an error.Option D (Incorrect): Misses the INTO keyword, which is required in standard SQL.Thus, the correct syntax is Option B, ensuring a properly formatted insert statement.
SQL INSERT Statement.
Post your Comments and Discuss WGU Data-Management-Foundations exam prep with other Community members:
Our website is free, but we have to fight against AI bots and content theft. We're sorry for the inconvenience caused by these security measures. You can access the rest of the Data-Management-Foundations content, but please register or login to continue.