SQL

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/40

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

41 Terms

1
New cards

SELECT DISTINCT

Selects Every unique value in a column

2
New cards

Order by ‘Age’ Descending

ORDER BY age DESC

3
New cards

How do you insert age = 9 and name = bob into every table column (table)?

INSERT INTO table

VALUES 9,bob

4
New cards

What is used to test if a value is NULL?

IS NULL

5
New cards

Update table ‘table’ so that column1 contains ‘5’

UPDATE table

SET column1 = 5

6
New cards

Update table ‘table’ so that column1 contains ‘5’ for customerID 1

UPDATE table

SET column1 = 5

WHERE customerID = 1

7
New cards

Delete CustomerID 1 in table ‘table’

DELETE table

WHERE CustomerID = 1

8
New cards

What is used to delete an entire table ‘table''

DROP TABLE table

9
New cards

Select the top 3 records from table ‘table’

SELECT TOP 3 * FROM table

10
New cards

Select the smallest price from column price in table ‘table’

SELECT MIN(Price) FROM table

11
New cards

Select the largest price from column ‘price’ in table ‘table’

SELECT MAX(Price) FROM table

12
New cards

Count the number of products in table ‘table’ that’s not NULL

SELECT COUNT(products) FROM table

13
New cards

Add all customerID’s together in table ‘table’

SELECT SUM(customerID) FROM table

14
New cards

Find the average price of products in table ‘table’

SELECT AVG(price) FROM table

15
New cards
16
New cards

Select all customers whose names start with ‘s’ from table ‘table’

SELECT customer FROM table WHERE customer LIKE ‘s%’

17
New cards

Select all customers whose name has two letters in table ‘table’

SELECT customer FROM table WHERE customer LIKE ‘__’

18
New cards

Select all from table ‘table’ where country = UK, Spain or US

SELECT * FROM table WHERE country IN (‘UK’,’SPAIN’,’US’)

19
New cards

Select all customers in table ‘table’ who have an order in table ‘orders’

SELECT customers FROM table WHERE Customer IN (SELECT customer FROM orders)

20
New cards

Select all customers from table ‘table’ where their age is between 10 and 20

SELECT customer FROM table WHERE age BETWEEN 10 AND 20

21
New cards

Select all customers from table ‘table’ and display it as customername from table ‘table’

SELECT customers AS customername FROM table

22
New cards

Join tables Orders and Customers on customer ID

SELECT * FROM Customers INNER JOIN Orders ON CustomerID.Customers = OrderID.Orders

23
New cards

Left Join tables Orders and Customers on customerID

SELECT * FROM Customers LEFT JOIN Orders ON customerID.Customers = customerID.Orders

24
New cards

In a Left Join, what records will be returned?

Records from the left table and records in both the left and right table.

25
New cards

Full join tables Orders and Customers on customerID

SELECT * FROM Orders FULL JOIN CustomerID.Customers = CustomerID.Orders

26
New cards

Select Distinct cities from Customers and Suppliers

SELECT City FROM Customers
UNION
SELECT City FROM Suppliers

27
New cards

Select cities (Including Duplicates) from Customers and Suppliers

SELECT City FROM Customers
UNION ALL
SELECT City FROM Suppliers

28
New cards

Count the number of customerID’s in each city in table ‘table’

SELECT COUNT(CustomerID), City FROM table GROUP BY City

29
New cards

When is HAVING used instead of WHERE?

When aggregate functions are used

30
New cards

make a backup of table ‘customers’ called ‘customersbackup’

SELECT * INTO CustomersBackup FROM Customers

31
New cards

Make a backup of table customers called customersbackup In an external database called externaldatabase

SELECT * INTO Customersbackup IN ‘externaldatabase’ FROM Customers

32
New cards

Insert table Orders Into table customers(Customers conatains ‘ customername’ and Orders contains ‘ OrderNumber’

INSERT INTO Customers(customer name) SELECT Orders (ordernumber) FROM Orders

33
New cards

In table customers, if customername is bob save to ‘output’ ‘name is bob’ else save ‘name is not bob’

SELECT Customername
CASE

WHEN customer name = ‘bob’ THEN ‘name is bob’

ELSE ‘name is not bob’

END AS output

FROM Customers

34
New cards

What does SELECT IFNULL(Orders,0) FROM table

Returns Order and 0 if orders is NULL

35
New cards
36
New cards
37
New cards
38
New cards
39
New cards
40
New cards
41
New cards