Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
brunj7 committed Apr 16, 2024
2 parents d69dd63 + 313b812 commit f8da819
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/week03/index-03.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ title: "Week 3 - Structured Query Language (SQL) & DuckDB"

Lecture notes:

(forthcoming)
- [lecture-notes-03-mon.txt](lecture-notes-03-mon.txt)

[ASDN dataset ER (entity-relationship) diagram](asdn-er-diagram.png)

Expand Down Expand Up @@ -45,4 +45,4 @@ Lecture notes:
5. Jeffrey D. Ullman and Jennifer Widom (2008). A First Course in Database Systems. 3rd ed. Upper Saddle River, NJ: Pearson/Prentice Hall.\
[Access via Library Catalog](https://search.library.ucsb.edu/permalink/01UCSB_INST/1aqck9j/alma990032103790203776)

- *Complete but theoretical introduction to relational databases, data modeling, and relational algebra.*
- *Complete but theoretical introduction to relational databases, data modeling, and relational algebra.*
45 changes: 45 additions & 0 deletions modules/week03/lecture-notes-03-mon.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Running DuckDB
- no argument: in-memory database, will disappear when closed
- or new file
- or existing file
- use .exit or Ctrl-D to get out

Getting around DuckDB
- dot commands
- .help
- .help <cmd> to get help on command
- .tables to list tables, .schema to list table definitions

Getting help
- .help
- SQLite's SQL railroad diagrams on website

SQL syntax
- SELECT * FROM Species;
- case-insensitive, both keywords and table/column names
- sources of confusion, DuckDB keeps prompting:
-- when missing trailing ;
-- when there's a quoted string and missing trailing '
-- how to abandon? Ctrl-C
- -- to comment

SELECT *
- LIMIT, OFFSET
- SELECT * from Site
- can select individual columns

SELECT DISTINCT
- SELECT DISTINCT Species FROM Bird_nests;
- SELECT DISTINCT Species, Observer FROM Bird_nests;
- distinct pairs ^^

ORDER BY
- SELECT DISTINCT Species FROM Bird_nests ORDER BY Species;
- order is random otherwise, particulary after table updates
- as above, order by Species
- as above by Species, Date_found DESC

In-class challenge
- Select distinct locations, are they in order? If not, order them.
- Does adding a limit apply after the results are ordered or before?
- Refer back to syntax chart - syntax echoes processing order.

0 comments on commit f8da819

Please sign in to comment.