SQL Part 1 Flashcards

(22 cards)

1
Q

What keyword is used for alias’s?

A

AS

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

Can you use string literals? If so, what would you use?

A

Yes, single quotes

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

What happens with the following line: SELECT 0 as id FROM Student

A

All student ID’s will show up as 0’s

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

What is the syntax for pattern matching?

A

LIKE ‘%_%’ where _ is any one character and % can mean any character. % can be placed between, before, and after characters.

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

List all students, sort them by GPA (descending) then name (ascending). The Student table has columns name and GPA.

A

SELECT GPA, name FROM Student ORDER BY GPA DESC, name;

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

Show me the names and phone numbers of passengers whose phone numbers have exactly two 7’s. Table is PASSENGER with columns passengername, phone

A

SELECT passengername, phone
FROM passenger
WHERE phone LIKE ‘%7%7%’ AND NOT phone LIKE ‘%7%7%7%’

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

Which semantics are set to default by SQL, Set or Bag?

A

Bag

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

What keyword is used to remove duplicates?

A

DISTINCT

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

What is used to access qualifying names and specific data structures? What is the format?

A

The ‘.’ symbol. Format: schema_name.table_name.column_name

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

How do you explicitly state there is a single quote in your equivalency statement?

A

Use another single quote, so ‘’

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

From Beers(name, manf), find all pairs of beers made by the same manufacturer.

A

SELECT b1.name, b2.name
FROM Beers b1, Beers b2
WHERE b1.manf = b2.manf and b1.name <> b2.name;

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

How do you say NOT EQUAL in SQL?

A

<> or !=

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

What is the syntax of a join statement?

A

Table1 JOIN Table2 ON Table1.Attribute = Table2.Attribute

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

Using Likes(drinker, beer), Sells(bar, beer, price), and Frequents(drinker, bar), find the drinkers and beers such that:
1. The drinker likes the beer
2. The drinker frequents at least one bar that sells the beer

A

(SELECT * FROM Likes) INTERSECT (SELECT drinker, beer FROM Sells, Frequents WHERE Frequents.bar = Sells.bar);

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

What subquery keywords are used for combination/omission of their sets with each other?

A

UNION, INTERSECT, DIFFERENCE

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

What are all aggregate SQL functions?

A

MIN(), MAX(), COUNT(), AVG(), SUM()

17
Q

How do NULL’s work in operations?

A

The result will become NULL when operating on it.

18
Q

Whats the difference between INNER JOIN and OUTER JOIN?

A

INNER JOIN (JOIN) only includes the rows that match between the two tables. OUTER JOIN includes all rows in both tables, even if there was no match between the two.

19
Q

Using Sells(bar, beer, price), find the bars that serve Miller for the same price Joe’s Bar charges for Bud.

A

SELECT bar
FROM Sells
WHERE beer = ‘Miller’ AND
price = (SELECT price
FROM Sells
WHERE bar = ‘Joe’’s Bar’ AND beer = ‘Bud’)

19
Q

What symbol is used to query all rows?

20
Q

Find beers liked by at least one person who frequents Joe’s Bar. Use the following tables: Likes(drinker, beer) Frequents(drinker, bar)

A

SELECT beer
FROM Likes, (SELECT drinker FROM Frequents WHERE bar = ‘Joe’’s Bar’)JD
WHERE Likes.drinker = JD.drinker;

21
Q

Find the department names that have no employees. departments(id, name) employees(id, name, department_id)

A

SELECT name FROM departments WHERE id NOT IN (SELECT department_id FROM employees)