DATABASE Flashcards

1
Q

WHAT IS A ROW IN A DATABASE?

A

record

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

WHAT IS A COLUMN IN A DATABASE?

A

field

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

SELECT *
FROM country;

A

get all columns from country table

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

SELECT id, name
FROM city;

A

fetches id and name columns from city table

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

SELECT name
FROM city
ORDER BY rating (ASC);

A

selects name column from city table and sorts it by rating in ascending order

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

SELECT name
FROM city
ORDER BY rating (DESC);

A

selects name column from city table and sorts it by rating in descending order

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

SELECT name
FROM city
WHERE rating > 3;

A

fetch names from city table where the rating is above 3

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

SELECT name
FROM city
WHERE name != ‘Berlin’
AND name != ‘Madrid’;

A

fetch names from city table that are neither Berlin or Madrid

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

SELECT name
FROM city
WHERE name LIKE ‘P%’
OR name LIKE ‘%s’ ;

A

fetch names of cities where their names start with P or ends in S

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

SELECT name
FROM city
WHERE name LIKE ‘_ublin’;

A

fetch names of cities with any letter followed by ‘ublin’

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

SELECT name
FROM city
WHERE population BETWEEN 50000 AND 5000000;

A

select names of cities where population is between 50K and 5M

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

SELECT name
FROM city
WHERE rating IS NOT NULL;

A

fetch names of cities where their rating does not miss a value

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

SELECT name
FROM city
WHERE country_id IN (1, 4, 7, 8);

A

fetch names of cities that are in countries with IDs 1, 4, 7, and 8

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

WHAT DOES “INNER JOIN” do?

SELECT city.name, country.name
FROM city
[INNER] JOIN country
ON city.country_id = country.id;

A

returns rows that have matching values in both tables

ex.
SELECT city.name, country.name
FROM city
INNER JOIN country
ON city.country_id = country.id;

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

WHAT DOES “LEFT JOIN” DO?

SELECT city.name, country.name
FROM city
LEFT JOIN country
ON city.country_id = country.id;

A

returns all rows from the left table with corresponding rows from the right table

if there’s no matching row, NULLs are returned as values from the second table

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

WHAT DOES “RIGHT JOIN” DO?

SELECT city.name, country.name
FROM city
RIGHT JOIN country
ON city.country_id = country.id;

A

returns all rows from the right table with corresponding rows from the left table

if there’s no matching row, NULLs are returned as values from the left table

17
Q

WHAT DOES “FULL JOIN” DO?

SELECT city.name, country.name
FROM city
FULL JOIN country
ON city.country_id = country.id;

A

returns all rows from both tables

18
Q

WHAT DOES “CROSS JOIN” do?

SELECT city.name, country.name
FROM city
CROSS JOIN country;

SELECT city.name, country.name
FROM city, country;

A

returns all possible combinations of rows from both tables

19
Q

WHAT DOES “NATURAL JOIN” DO?

SELECT city.name, country.name
FROM city
NATURAL JOIN country;

A

joins tables by all columns with the same name

20
Q

WHAT DOES “ALTER TABLE” DO?

ALTER TABLE table_name
ADD column_name datatype;

A

allows you to add columns to a table in database

21
Q

WHAT DOES “AS” DO?

SELECT column_name AS ‘ALIAS’
FROM table_name;

A

allows you to rename a column or table using an alias