Skip to content

Instantly share code, notes, and snippets.

@artem-alek
Created March 6, 2017 21:46
Show Gist options
  • Save artem-alek/da0ce699944d159f0fb2ac775e34891c to your computer and use it in GitHub Desktop.
Save artem-alek/da0ce699944d159f0fb2ac775e34891c to your computer and use it in GitHub Desktop.
Normal Mode:
1. SELECT COUNT(users.id) FROM users;
50
2. SELECT items.title FROM items ORDER BY items.price DESC LIMIT 5;
title
Small Cotton Gloves
Small Wooden Computer
Awesome Granite Pants
Sleek Wooden Hat
Ergonomic Steel Car
3. SELECT category,title FROM items WHERE category LIKE '%books%' ORDER BY items.price ASC LIMIT 1;
category|title
Books|Ergonomic Granite Chair
4. SELECT * FROM users
...> INNER JOIN addresses ON addresses.user_id=users.id
...> WHERE users.id = '40';
id|first_name|last_name|email|id|user_id|street|city|state|zip
40|Corrine|Little|[email protected]|43|40|6439 Zetta Hills|Willmouth|WY|15029
40|Corrine|Little|[email protected]|44|40|54369 Wolff Forges|Lake Bryon|CA|31587
5. UPDATE addresses
...> SET zip = '12345'
...> WHERE id = 41;
6. SELECT SUM(quantity)
...> FROM orders;
2125
7. INSERT INTO users (first_name,last_name,email)
...> VALUES('Artem','Aleksandruk','[email protected]');
INSERT INTO orders (user_id,item_id,quantity,created_at)
...> VALUES (51,88,3,'2015-02-09 00:40:30.460741');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment