Skip to content

Instantly share code, notes, and snippets.

@dlyapun
Created October 7, 2019 12:39
Show Gist options
  • Save dlyapun/4f2ca195d23bf910b11346cb8d5d7512 to your computer and use it in GitHub Desktop.
Save dlyapun/4f2ca195d23bf910b11346cb8d5d7512 to your computer and use it in GitHub Desktop.
CREATE TABLE STUDENTS (
ID INTEGER PRIMARY KEY,
FIRST_NAME VARCHAR(50) NOT NULL,
LAST_NAME VARCHAR(50) NOT NULL,
ADDRESS VARCHAR(100)
);
CREATE TABLE ORDERS
(
Id INTEGER PRIMARY KEY,
StudentId INTEGER,
test ARCHAR(100),
FOREIGN KEY (StudentId) REFERENCES STUDENTS (id)
);
INSERT INTO students VALUES (1, 'Dima', 'Lyapun', NULL);
INSERT INTO students VALUES (2, 'Ivan', 'Ivanon', 'My address');
INSERT INTO students VALUES (3, 'Alex', 'Cooper', 'Odessa, Ua');
INSERT INTO students VALUES (4, 'Alex', 'Second', 'Odessa, Ua');
UPDATE students SET first_name = 'Dmytro', last_name = 'Lyao' WHERE first_name = 'Dima';
INSERT INTO ORDERS VALUES (1, 2, 'Simple Order data');
SELECT first_name, last_name from STUDENTS WHERE id = 1;
SELECT id, last_name from STUDENTS WHERE id > 2 ;
SELECT first_name from STUDENTS GROUP BY first_name;
SELECT last_name from STUDENTS WHERE id < 3 ORDER BY last_name;
SELECT * FROM ORDERS INNER JOIN STUDENTS ON orders.StudentId = Students.id;
SELECT id, first_name, last_name from STUDENTS WHERE id = 2 AND first_name = 'Ivan';
SELECT first_name, last_name from STUDENTS WHERE id IN (2,3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment