Screen Shot 2021-10-06 at 11.20.11 PM.png

SELECT title, instructor FROM Class WHERE dept = 'CS';

Basic SQL SELECT statement

Screen Shot 2021-10-06 at 11.24.01 PM.png

If we want to remove duplicates, we need to add DISTINCT after SELECT

SELECT DISTINCT * FROM Enroll;
# ^ those commands are actually case-insensitive, but the name of the tables are not

Screen Shot 2021-10-06 at 11.29.23 PM.png

SELECT DISTINCT name, GPA # distinct will only remove duplicates for the selected tuple
FROM Enroll E,Student S # join Enroll and Student and rename the column name
WHERE dept='CS' AND E.sid=S.sid; 

Screen Shot 2021-10-06 at 11.32.45 PM.png

SELECT name, GPA
FROM Student
WHERE addr LIKE '%Wilshire%';
# LIKE: instead of interpreting as a regular string, interpret them as string with 
# special commands
# % : string with any length
# _ : one character

2 queries are logical equivalent if and only if the 2 queries returns exactly the same tuples under any database instances

Set Operators in SQL