Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sql tables #1

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions sql/data_inserts.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
-- insert one ROW
-- insert multiple ROWS

INSERT INTO employers
(name)
VALUES
("MaxwellHealth"),
("WeSpire");

SELECT *
FROM employers;

DELETE
FROM employers
WHERE name = "MaxwellHealth";
-- WHERE id = 11

INSERT
INTO employers
(name)
VALUES
("MaxwellHealth"),
("WeSpire"),
("Adrian"),
("Annabelle");

SELECT id, name
FROM employers
WHERE name LIKE '%ax%';

INSERT INTO members (employedId, name)
VALUES

(1, "Michael"),
(1, "Darryl");

SELECT employers.name, members.name
FROM employers
JOIN members
ON employers.id = members.employedId;

7 changes: 7 additions & 0 deletions sql/dates.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
SELECT NOW();

SELECT SYSDATE();

SELECT CURDATE();

SELECT NOW(), SYSDATE(), CURDATE();
12 changes: 12 additions & 0 deletions sql/employers.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-- id and name columns
-- id INT
-- name VARCHAR
-- PK to define primary key

CREATE TABLE
IF NOT EXISTS employers
(
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(225) NOT NULL UNIQUE,
PRIMARY KEY (id)
);
7 changes: 7 additions & 0 deletions sql/group_by.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- get a count of numbers by employer

SELECT employers.name, count(members.name) AS member_count
FROM employers
JOIN members
ON employers.id = members.employedId
GROUP BY employers.name
9 changes: 9 additions & 0 deletions sql/members.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE
IF NOT EXISTS members
(
id INT AUTO_INCREMENT NOT NULL,
name VARCHAR(225) NOT NULL UNIQUE,
employedId INT,
PRIMARY KEY (id),
FOREIGN KEY (employedId) REFERENCES employers (id)
);
10 changes: 10 additions & 0 deletions sql/order_by.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
SELECT *
FROM members
ORDER BY name;

SELECT employers.name, employers.id,
members.name, members.id
FROM employers
JOIN members
ON employers.id = members.employedId
ORDER BY employers.name, members.name
19 changes: 19 additions & 0 deletions sql/strings.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- mid
-- left
-- right
-- upper
-- lower
-- concat


-- using the mid, give me the index char of these positions
SELECT MID("TEST", 1,2)

-- first 3 char
SELECT LEFT("LONG STRING", 3)

SELECT UPPER(members.name) AS name
FROM members

SELECT CONCAT(members.name, " is awesome.") AS name
FROM members
54 changes: 54 additions & 0 deletions sql/where.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

SELECT employers.name, members.name
FROM employers
JOIN members
ON employers.id = members.employedId
WHERE members.name = 'Rory';

SELECT employers.name, members.name
FROM employers
JOIN members
ON employers.id = members.employedId
WHERE employers.name = 'MaxwellHealth';

SELECT employers.name, employers.id,
members.name, members.id
FROM employers
JOIN members
ON employers.id = members.employedId
-- WHERE employers.name = 'MaxwellHealth';

SELECT employers.name, employers.id,
members.name, members.id
FROM employers
JOIN members
ON employers.id = members.employedId
WHERE employers.id = 1;

SELECT employers.name, employers.id,
members.name, members.id
FROM employers
JOIN members
ON employers.id = members.employedId
WHERE members.id = 51;

SELECT employers.name, employers.id,
members.name, members.id
FROM employers
JOIN members
ON employers.id = members.employedId
WHERE members.name LIKE '%or%';

INSERT INTO members (employedId, name)
VALUES
(1, "Rory"),
(1, "Julie"),
(1, "Kyle"),
(1, "Jerry"),
(1, "George"),
(1, "Michael"),
(1, "Darryl");

SELECT *
FROM employers;