SQL lab test 1
SQL lab test 1
1. Insert the missing statement to get all the columns from the Customers table.
* FROM Customers;
2. Write a statement that will select the City column from the Customers table.
Customers;
3. Select all records where the City column has the value "Berlin".
= ;
4. Select all records where the CustomerID column has the value 32.
CustomerID ;
5. Select all records where the City column has the value
'Berlin' and the PostalCode column has the value '12209'.
* FROM Customers
City = 'Berlin'
= '12209';
6. Select all records where the City column has the value 'Berlin' OR 'London'.
* FROM Customers
City = 'Berlin'
=' ';
7. Select all records from the Customers where the PostalCode column is empty.
WHERE ;
8. Select all records from the Customers where the PostalCode column is NOT empty.
WHERE ;
Customers
City = 'Oslo';
10. Set the value of the City columns to 'Oslo', but only the ones where
the Country column has the value "Norway".
Customers
City = 'Oslo'
Country = 'Norway';
Customers
City = 'Oslo'
= 'Norway'
12. Delete all the records from the Customers table where the Country value is 'Norway'.
Customers
Country = 'Norway';
Customers;
14. Use the MIN function to select the record with the smallest value of the Price column.
SELECT
FROM Products;
15. Use an SQL function to select the record with the highest value of the Price column.
SELECT
FROM Products;
16. Select all records where the value of the City column starts with the letter "a".
17. Select all records where the value of the City column ends with the letter "a".
18. Select all records where the value of the City column contains the letter "a".
19. Select all records where the value of the City column does NOT start with the letter
"a".
20. Select all records where the second letter of the City is an "a".
21. Use the IN operator to select all the records where Country is either "Norway" or
"France".
'France' ;
22. Use the IN operator to select all the records where Country is NOT "Norway" and
NOT "France".
('Norway', 'France');
23. Use the BETWEEN operator to select all the records where the value of
the Price column is between 10 and 20.
WHERE Price ;
24. Use the BETWEEN operator to select all the records where the value of
the ProductName column is alphabetically between 'Geitost' and 'Pavlova'.
WHERE ProductName ;
25. When displaying the Customers table, make an ALIAS of the PostalCode column, the
column should be called Pno instead.
SELECT CustomerName,
Address,
PostalCode
FROM Customers;
26. When displaying the Customers table, refer to the table as Consumers instead
of Customers.
SELECT *
FROM Customers ;
29. Select all records from the Customers table, sort the result alphabetically, first by
the column Country, then, by the column City. (use order by)
30.Write the correct SQL statement to create a new database called testDB.