SQL Flashcards

1
Q

Q: What SQL clause is used to filter rows based on a specified condition?

Example:

How do you select employees with a salary greater than 5000?

A

A: The WHERE clause is used to filter rows based on a specified condition.

Example:

SELECT *
FROM Employees
WHERE salary > 5000;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q: Which SQL keyword is used to sort the result set in ascending or descending order?

Example:

How do you sort employees by their last names in ascending order?

A

A: The ORDER BY keyword is used to sort the result set in ascending or descending order.

Example:

SELECT *
FROM Employees
ORDER BY last_name ASC;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q: How do you select all columns from a table named “Customers”?

Example:

Write a query to select all data from the Customers table.

A

SELECT *
FROM Customers;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q: What SQL function is used to count the number of rows in a result set?

Example:

How do you count the number of employees in the Employees table?

A

A: The COUNT() function is used to count the number of rows in a result set.

Example:

SELECT COUNT(*)
FROM Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q: How do you retrieve unique values from a column named “City” in a table named “Employees”?

Example:

Write a query to get unique cities from the Employees table.

A

SELECT DISTINCT City
FROM Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q: What SQL clause is used to group rows that have the same values in specified columns?

Example:

How do you group employees by their job titles?

A

A: The GROUP BY clause is used to group rows that have the same values in specified columns.

Example:

SELECT job_title, COUNT(*)
FROM Employees
GROUP BY job_title;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q: Which SQL keyword is used to remove duplicate records from a result set?

Example:

How do you select unique job titles from the Employees table?

A

A: The DISTINCT keyword is used to remove duplicate records from a result set.

Example:

SELECT DISTINCT job_title
FROM Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q: What SQL function is used to calculate the average value of a numeric column?

Example:

How do you find the average salary of all employees?

A

A: The AVG() function is used to calculate the average value of a numeric column.

Example:

SELECT AVG(salary)
FROM Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q: How do you rename a column in the result set using an alias?

Example:

How do you select the first name of employees and rename it to ‘FirstName’ in the result set?

A

A: Use the AS keyword to rename a column in the result set.

Example:

SELECT first_name AS FirstName
FROM Employees;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q: What SQL keyword is used to combine rows from two or more tables, based on a related column between them?

Example:

How do you join Employees and Departments tables to get the department names for each employee?

A

A: The JOIN keyword is used to combine rows from two or more tables based on a related column between them.

Example:

SELECT Employees.first_name, Employees.last_name, Departments.department_name
FROM Employees
JOIN Departments ON Employees.department_id = Departments.department_id;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly