Skip to content

Instantly share code, notes, and snippets.

@toyeiei
Last active July 31, 2018 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toyeiei/4c80e6523fa7eb09e1a8fe5725277b35 to your computer and use it in GitHub Desktop.
Save toyeiei/4c80e6523fa7eb09e1a8fe5725277b35 to your computer and use it in GitHub Desktop.
Introduction to SQL for everyone part I
-- SELECT clause to select specific columns
-- Select all columns from customers table
SELECT * FROM customers;
-- Select firstname, lastname and address columns from customers table
SELECT firstname, lastname, address FROM customers;
-- Use AS (alias) to change the column name
SELECT
firstname AS customer_firstname,
lastname AS customer_lastname
FROM
customers;
-- Calculate new columns
SELECT revenue - expenditure AS profit
FROM finances;
-- WHERE clause to filter rows
-- Select customers who live in Thailand
SELECT * FROM customers
WHERE country = 'Thailand';
-- Select customers who live in Thailand or Canada
SELECT * FROM customers
WHERE country = 'Thailand' OR country = 'Canada';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment