Last active
November 1, 2017 17:55
-
-
Save mattm/5f7c02e8659f2a9f77afeb9d5e4880eb to your computer and use it in GitHub Desktop.
COUNT Example Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS users; | |
CREATE TABLE users (user_id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(20)); | |
INSERT INTO users (name) VALUES ('Matt'); | |
INSERT INTO users (name) VALUES ('Simon'); | |
INSERT INTO users (name) VALUES ('Jen'); | |
DROP TABLE IF EXISTS posts; | |
CREATE TABLE posts (post_id INT PRIMARY KEY AUTO_INCREMENT, user_id INT); | |
INSERT INTO posts (user_id) VALUES (1); | |
INSERT INTO posts (user_id) VALUES (1); | |
INSERT INTO posts (user_id) VALUES (1); | |
INSERT INTO posts (user_id) VALUES (2); | |
INSERT INTO posts (user_id) VALUES (2); | |
DROP TABLE IF EXISTS pages; | |
CREATE TABLE pages (page_id INT PRIMARY KEY AUTO_INCREMENT, user_id INT); | |
INSERT INTO pages (user_id) VALUES (2); | |
INSERT INTO pages (user_id) VALUES (2); | |
INSERT INTO pages (user_id) VALUES (3); | |
INSERT INTO pages (user_id) VALUES (3); | |
INSERT INTO pages (user_id) VALUES (3); | |
INSERT INTO pages (user_id) VALUES (3); | |
INSERT INTO pages (user_id) VALUES (3); | |
+---------+-------+ | |
| user_id | name | | |
+---------+-------+ | |
| 1 | Matt | | |
| 2 | Simon | | |
| 3 | Jen | | |
+---------+-------+ | |
+---------+---------+ | |
| post_id | user_id | | |
+---------+---------+ | |
| 1 | 1 | | |
| 2 | 1 | | |
| 3 | 1 | | |
| 4 | 2 | | |
| 5 | 2 | | |
+---------+---------+ | |
+---------+---------+ | |
| page_id | user_id | | |
+---------+---------+ | |
| 1 | 2 | | |
| 2 | 2 | | |
| 3 | 3 | | |
| 4 | 3 | | |
| 5 | 3 | | |
| 6 | 3 | | |
| 7 | 3 | | |
+---------+---------+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment