Structured Query
Language (SQL)
I. Main Applications (Trevor S)
● Database applications
○
Creating, reading, deleting, modifying
● Web applications
○
Store and retrieve user information
● Backend systems for apps and services
○
Supports apps, servies, and APIs
Examples:
● Analyze sales trends from company data
● Retrieve user information from a website database
● Filter millions of records in seconds
II. Any required Software/GUI/Compilers? -Jacob
Required: Database Engine
Optional: Graphic Interface Tool
Not Required:
Popular GUIs:
Examples:
●
MySQL
●
PostgreSQL
●
Microsoft SQL Server
●
Oracle Database
●
SQLite (very lightweight)
●
●
●
●
These engines interpret SQL — no
compiler needed.
●
MySQL Workbench (for
MySQL)
pgAdmin (for PostgreSQL)
SQL Server Management
Studio (SSMS) (for SQL
Server)
DBeaver (works with any
database)
Azure Data Studio (also
multi-database)
GUIs are optional but you can run
SQL from the command line but they
make life easier.
No compiler
●
SQL is interpreted by the
database engine.
No special IDE
●
Any text editor works, though
GUIs help.
III. Arrays, Built in Functions (Joseph L)
MATLAB:
●
●
●
Common Built in SQL Functions:
Uses arrays for storing data
Access with indexing (e.g. data(1))
Loop through values manually
SQL:
●
●
●
Uses tables (rows & columns) instead of arrays
Each column is a list of values
No need for manual looping
MathLab:
data = [90, 80, 70];
disp(data(1))
Output: 90
Sql:
Table: Table1
numbers
———
90
80
70
SELECT numbers FROM
Table1;
●
●
●
●
●
AVG() → average
MAX() → maximum
MIN() → minimum
COUNT() → number of rows
SUM() → total
Relatively similar to MathLab but also has some
unique functions because of its table system:
GROUP BY → groups data before applying functions
HAVING → filters grouped results
DISTINCT → removes duplicates
III. Conditionals (Alejandro)
-
In MATLAB you use if/elseif/else to branch logic, or logical indexing to filter arrays.
SQL uses WHERE to filter rows, and CASE WHEN to create conditional columns,
there's no "if statement" you write manually because the database engine handles the
looping for you.
MATLAB — if/else branch
grade = 85;
if grade >= 90
disp('A')
elseif grade >= 80
disp('B')
else
disp('C')
end
SQL — CASE WHEN column
SELECT name, grade,
CASE
WHEN grade >= 90 THEN 'A'
WHEN grade >= 80 THEN 'B'
ELSE 'C'
END AS letter
FROM students;
III. User-defined functions
-
-
MATLAB lets you write reusable functions that take inputs, run calculations, and return
outputs.
SQL is not a general programming language, so it doesn't have functions in the same
sense. Most databases do support stored procedures or user-defined functions (UDFs),
but they are rarely used for everyday queries.
The SQL equivalent is usually writing a reusable query.
MATLAB — user function
function result = celsiusToF(c)
result = (c * 9/5) + 32;
end
% Call it:
temp = celsiusToF(100);
% → 212
SQL — inline formula instead
SELECT city, temp_c,
(temp_c * 9.0/5) + 32
AS temp_f
FROM weather;
-- No function needed —
-- formula runs on every row
III. While Loops, For Loops (Jack T)
-
In SQL, loops are usually less
common.
- Instead, SQL use set-based
operation.
+ Working whole group of rows at
the same time.
Examples: Data Validation
MATLAB:
SQL:
data = [3, 5, -2, 7];
SELECT
i = 1;
data,
while i <= length(data)
CASE
if data(i) > 0
disp("Valid")
else
disp("Invalid")
end
i = i + 1;
end
WHEN data > 0 THEN 'Valid'
ELSE 'Invalid'
END AS status
FROM your_table;
Example: Find the mean of the values
MATLAB
SQL:
data = [2 4 6 8];
SELECT AVG(data) AS average_value
total = 0;
FROM your_table;
for i = 1:length(data)
total = total + data(i);
end
mean = total / length(data);
disp(mean)
IV. Brief comparison of pros and cons versus MATLAB? (Trevor S)
Pros:
● Handles large data sets more efficiently
● Faster for data retrieval and filtering
Cons:
● Worse at numerical computing or simulations
● Less in depth plotting or visualization
● Not as good for matrices or algorithims