Select An Entire Table

Note: This tutorial was written using Catherine Devlin's SQL in Jupyter Notebooks library. If you have not using a Jupyter Notebook, you can ignore the two lines of code below and any line containing %%sql. Furthermore, This tutorial uses SQLite's flavor of SQL, your version might have some differences in syntax.

# Ignore
%load_ext sql
%sql sqlite://
%config SqlMagic.feedback = False

Create Data

%%sql

/* Create A Table Of Criminals */
CREATE TABLE criminals (pid, name, age, sex, city, minor);
INSERT INTO criminals VALUES (412, 'James Smith', 15, 'M', 'Santa Rosa', 1);
INSERT INTO criminals VALUES (234, 'Bill James', 22, 'M', 'Santa Rosa', 0);
INSERT INTO criminals VALUES (632, 'Stacy Miller', 23, 'F', 'Santa Rosa', 0);
INSERT INTO criminals VALUES (621, 'Betty Bob', NULL, 'F', 'Petaluma', 1);
INSERT INTO criminals VALUES (162, 'Jaden Ado', 49, 'M', NULL, 0);
INSERT INTO criminals VALUES (901, 'Gordon Ado', 32, 'F', 'Santa Rosa', 0);
INSERT INTO criminals VALUES (512, 'Bill Byson', 21, 'M', 'Santa Rosa', 0);
INSERT INTO criminals VALUES (411, 'Bob Iton', NULL, 'M', 'San Francisco', 0);

/* Create A Table Of Crimes */
CREATE TABLE crimes (cid, crime, city, pid_arrested, cash_stolen);
INSERT INTO crimes VALUES (1, 'fraud', 'Santa Rosa', 412, 40000);
INSERT INTO crimes VALUES (2, 'burglary', 'Petaluma', 234, 2000);
INSERT INTO crimes VALUES (3, 'burglary', 'Santa Rosa', 632, 2000);
INSERT INTO crimes VALUES (4, NULL, NULL, 621, 3500); 
INSERT INTO crimes VALUES (5, 'burglary', 'Santa Rosa', 162, 1000); 
INSERT INTO crimes VALUES (6, NULL, 'Petaluma', 901, 50000); 
INSERT INTO crimes VALUES (7, 'fraud', 'San Francisco', 412, 60000); 
INSERT INTO crimes VALUES (8, 'burglary', 'Santa Rosa', 512, 7000); 
INSERT INTO crimes VALUES (9, 'burglary', 'San Francisco', 411, 3000); 
INSERT INTO crimes VALUES (10, 'robbery', 'Santa Rosa', 632, 2500); 
INSERT INTO crimes VALUES (11, 'robbery', 'Santa Rosa', 512, 3000);
[]

Select Each Everything In Teach Table

%%sql

-- Select everything
SELECT *

-- From the table 'criminals'
FROM criminals
pid name age sex city minor
412 James Smith 15 M Santa Rosa 1
234 Bill James 22 M Santa Rosa 0
632 Stacy Miller 23 F Santa Rosa 0
621 Betty Bob None F Petaluma 1
162 Jaden Ado 49 M None 0
901 Gordon Ado 32 F Santa Rosa 0
512 Bill Byson 21 M Santa Rosa 0
411 Bob Iton None M San Francisco 0
%%sql

-- Select everything
SELECT *

-- From the table 'crimes'
FROM crimes
cid crime city pid_arrested cash_stolen
1 fraud Santa Rosa 412 40000
2 burglary Petaluma 234 2000
3 burglary Santa Rosa 632 2000
4 None None 621 3500
5 burglary Santa Rosa 162 1000
6 None Petaluma 901 50000
7 fraud San Francisco 412 60000
8 burglary Santa Rosa 512 7000
9 burglary San Francisco 411 3000
10 robbery Santa Rosa 632 2500
11 robbery Santa Rosa 512 3000