SQL Practicals Flashcards
Get all the columns from the Customers table.
SELECT * FROM Customers;
Write a statement that will select the City column from the Customers table.
SELECT City FROM Customers;
Select all the different values from the Country column in the Customers table.
SELECT DISTINCT Country FROM Customers;
Select all the columns from the Customers table, then
Select all records where the City column has the value “Berlin”.
SELECT * FROM Customers WHERE City = ‘Berlin’;
Select all the columns from the Customers table, then
use the NOT keyword to select all records where City is NOT “Berlin”
SELECT * FROM Customers WHERE NOT City = ‘Berlin’;
Select all the columns from the Customers table, then select all records where the CustomerID column has the value 32.
SELECT * FROM Customers WHERE CustomerID = 32;
Select all the columns from the Customers table, then select all records where the City column has the value ‘Berlin’ AND the PostalCode column has the value 12209.
SELECT * FROM Customers WHERE City = ‘Berlin’ AND PostalCode = 12209;
Select all the columns from the Customers table, then select all records where the City column has the value ‘Berlin’ or ‘London’.
SELECT * FROM Customers WHERE City = ‘Berlin’ OR City = ‘London’;
Select all the columns from the Customers table, then sort the result alphabetically by the column City.
SELECT * FROM Customers ORDER BY City;
Select all the columns from the Customers table, then sort the result reversed alphabetically by the column City.
SELECT * FROM Customers ORDER BY City DESC;
Select all the columns from the Customers table, then sort the results alphabetically, first by column Country, then, by the column City.
SELECT * FROM Customers ORDER BY Country, City;
Insert a new record in the Customers table which includes CustomerName, Address, City, PostalCode, Country with the corresponding values of John Smith, 15 Wilson St, Detroit, 33303, USA.
INSERT INTO Customers ( CustomerName, Address, City, PostalCode, Country) VALUES ( John Smith, 15 Wilson St, Detroit, 33303, USA);
Select all the columns from the Customers table where the PostalCode column is empty.
SELECT * FROM Customers WHERE PostalCode IS NULL;
Select all the columns from the Customers table where the PostalCode is not empty.
SELECT * FROM Customers WHERE PostalCode IS NOT NULL;
Update the City column of all records in the Customers table with the City ‘Oslo’.
UPDATE Customers SET City = ‘Oslo’;