Operators Flashcards

1
Q

INTERSECT

A

Combines two SELECT statements and returns only the dataset that is common in both the statements

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

EXCEPT

A

Returns the distinct rows that are present in the result set of the first query but not in the result set of the second query.

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

LIKE

A

The LIKE command is used in a WHERE clause to search for a specified pattern in a column.

You can use two wildcards with LIKE:

% - Represents zero, one, or multiple characters
_ - Represents a single character (MS Access uses a question mark (?) instead)

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

REGEXP

A

Used to search for a specified pattern using regular expression pattern matches.

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

UNION

A

Combines the data from the result of two or more SELECT statements into a single result set. This operator removes any duplicates present in the results being combined.

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

UNION ALL

A

Combines the data from the result of two or more SELECT statements into a single result set. This operator DOES NOT REMOVE any duplicates present in the results being combined.

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

IS NULL

A

Used to test for empty values (NULL values).

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

AND

A

Displays a record if all the conditions stated in the query are TRUE.

Example:
SELECT * FROM Customers
WHERE Country = ‘Germany’
AND City = ‘Berlin’
AND PostalCode > 12000;

This will display all Customers that are located in Berlin, Germany with a postal code 12000.

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

OR

A

Displays a record in which any of the conditions stated in the query are TRUE.

Example:
SELECT * FROM Customers
WHERE Country = ‘Germany’
OR City = ‘Berlin’
OR PostalCode > 12000;

This will display all Customers that are located in any city named Berlin (regardless of the country it’s in), customer in any city in Germany and customers that have their postal code as 12000.

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

=

A

Returns values that are “Equal To” the value input in the query

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

>

A

Returns values that are “Greater Than” the value input in the query

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

<

A

Returns values that are “Less Than” the value input in the query

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

> =

A

Returns values that are “Equal To or Greater Than” the value input in the query

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

<=

A

Returns values that are “Equal To or Less Than” the value input in the query

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

<>

A

Returns values that are “NOT Equal To” the value input in the query

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

%

A

This represents the “modulo”. It is used to get the remainder from a division.

17
Q

IN

A

The IN operator allows you to specify multiple values in a WHERE clause. Example:

SELECT customerName, state
FROM customers
WHERE state IN (‘MA’, ‘CA’, ‘PA’)

This will return all of the customers that are registered in the database “customers” as located in the states of MA (Massachussets), CA (California) or PA (Pennsylvania).

18
Q

NOT IN

A

The NOT IN operator will return all records that are NOT any of the values in the list in a WHERE clause.
Example:

SELECT customerName, country
FROM customers
WHERE state NOT IN (‘USA’, ‘France’, ‘Germany’)

This will return all of the customers that are registered in the database “customers” and are NOT located in USA, France or Germany.

19
Q

CROSS JOIN

A

Used to generate a paired combination of each row of the first table with each row of the second table.

20
Q

INNER JOIN

A

Selects records that have matching values in both tables.

21
Q

When using a JOIN operator, if both tables are using the same field name what syntax could you use to call for that specific field in each table?

A

USING (nameofthefield);

22
Q

When using a JOIN operator, if the fields on each table do NOT share the same name, what syntax should you use to call for that specific field from each table?

A

ON table1.nameofthefield = table2.nameofthefieldonthistable

23
Q

Which table will LEFT JOIN retrieve the information from?

A

The first table

24
Q

Which table will RIGHT JOIN retrieve the information from?

A

The second table

25
Q

LEFT JOIN or LEFT OUTER JOIN

A

Returns all records from the left table (table1), and the matching records from the right table (table2)

26
Q

RIGHT JOIN or RIGHT OUTER JOIN

A

Returns all records from the right table (table2), and the matching records from the right table (table1)

27
Q

SELF JOIN

A

Used to join a table to itself as if the table were two tables

28
Q

What do you need to specify in a SELF JOIN?

A

The table aliases

29
Q

ORDER BY

A

Used to sort the fetched data in either ascending or descending according to one or more columns. If not specified it will order in ascending order by default.

SELECT column1, column2, …
FROM table_name
ORDER BY column1, column2, … ASC|DESC;

30
Q

What keyword do you need to add to the ORDER BY syntax to organize the results in ascending order?

A

ASC

31
Q

What keyword do you need to add to the ORDER BY syntax to organize the results in descending order?

A

DESC

32
Q

What function can we use to sort the results in a customized sort order?

A

field

33
Q

LIMIT

A

Used to return a limited number of records.

SELECT * FROM Customers
LIMIT 3;

You can also specify the starting point.

SELECT * FROM Customers
LIMIT 100, 3;

The ‘100’ is specifying the line number you want the query to start from. If not specified, it will automatically start from the first line.

34
Q

GROUP BY

A

Groups rows that have the same values into summary rows, like “find the number of customers in each country”.

35
Q

HAVING

A

Filters a result set to ONLY include records that fulfill a specified condition. It is used in aggregate functions instead of the clause WHERE, which doesn’t work in aggregate functions.

36
Q

What keyword do we use instead of WHERE in an aggregate function to meet certain conditions?

A

HAVING

WHERE does not work in aggregate functions

37
Q

WITH ROLLUP

A

Is an extension of the GROUP BY clause that produces sub-total of each group set (in addition to the grouped rows).

38
Q

EXIST

A