1 of 12

CSE 414: Section 2

A SeQueL to SQL

October 8th, 2026

2 of 12

Announcements

  • HW1 due tomorrow, 10/09 at 11:59 PM
    • You can use up to 2 late days per assignment
    • Late deadline 10/11 at 11:59pm
  • Office hours have been posted!
    • Tanvi’s are Friday’s 2:30-3:30pm in the Allen 2nd Floor Breakout Room
  • HW2 released tomorrow, due 10/16 @ 11:59pm
    • Name the files EXACTLY as specified

3 of 12

Importing Files (HW2)

First, create the table.�Then, import the data.

.mode csv� .import population.csv Population� .import gdp.csv GDP

.import /path/to/file NameOfTable

Make sure you import the tables in the order you create them so there are no foreign key constraint issues. For example, if GDP had a foreign key constraint to Population, it would be illegal to import GDP before Population.

3

4 of 12

SQL 3-Valued Logic

SQL has 3-valued logic

  • FALSE = 0

[ex] price < 25 is FALSE when price = 99

  • UNKNOWN = 0.5

[ex] price < 25 is UNKNOWN when price = NULL

  • TRUE = 1

[ex] price < 25 is TRUE when price = 19

4

5 of 12

SQL 3-Valued Logic (con’t)

Formal definitions where C1 and C2 are conditions:

C1 AND C2 means min(C1, C2)� C1 OR C2 means max(C1, C2)� NOT C1 means means 1 - C1

​

The rule for SELECT ... FROM ... WHERE C is the following:� if C = TRUE then include the row in the output� if C = FALSE or C = unknown then do not include it

5

6 of 12

Aliasing

  • Good style for renaming attribute operations to more intuitive labels
  • Essential for self joins (ex: FROM [table] AS T1, [table] AS T2)
  • You can alias without “AS” in the FROM clause (i.e. “AS” keyword can be omitted)

SELECT [attribute] AS [attribute_name]

FROM [table] AS [table_name]

… [table_name].[attribute_name] …

​

​

6

7 of 12

Misc. Filters

LIMIT number - limits the amount of tuples returned

[ex] SELECT * FROM table LIMIT 1;

DISTINCT - only returns unique values (eliminates duplicates)

[ex] SELECT DISTINCT column_name FROM table;

​

7

8 of 12

Join Semantics

  • Think as “nested loops”.

​

  • NOT the most efficient implementation on a large database! (we will talk about other ways to join later in the course)
  • Hash Join
  • Sort-Merge Join

8

For more information and different types of joins see:

https://blogs.msdn.microsoft.com/craigfr/2006/08/16/summary-of-join-properties/

​

9 of 12

Nested Loop Semantics

SELECT x_1.a_1, …, x_n.a_n�FROM x_1, …, x_n�WHERE <cond>

​

for each tuple in x_1:

…

for each tuple in x_n:

if <cond>(x_1, …, x_n):

output(x_1.a_1, …, x_n.a_n)

9

10 of 12

Join Types

There will be times we use inner join, full outer join, and left outer join.

There is never a scenario in this class we need to use a right outer join and you most likely won’t need full outer join for this class.

10

11 of 12

Acronym to Remember Order

FWGHOS

(From, Where, Group By, Having, Order By, Select)

11

12 of 12

Worksheet