Jed Rembold
Wednesday, September 17, 2025
Suppose you have a table of items with the schema shown below and wanted to find the most common difference between Price A and Price B. You are looking for bargains, so in the case of a tie, you’d like to know the biggest. Which query will deliver on your wish?
CREATE TABLE rev (
"name" TEXT,
"pa" NUMERIC(4,2),
"pb" NUMERIC(4,2)
);
SELECT mode(pb) - mode(pa) AS com_dif
FROM rev
ORDER BY com_dif;
SELECT
mode() WITHIN GROUP (ORDER BY pb) -
mode() WITHIN GROUP (ORDER BY pa)
FROM rev;
SELECT
mode() WITHIN GROUP (ORDER BY (pb-pa))
FROM rev;
SELECT
mode() WITHIN GROUP (ORDER BY (pb-pa) DESC)
FROM rev;

SELECT * FROM |||table A|||
JOIN |||table B|||
ON |||table a|||.|||key column||| = |||table b|||.|||key column|||;
SELECT tab1.name, tab1.age, tab2.name
FROM tab1
JOIN tab2 ON tab1.age = tab2.age;
SELECT *
FROM facebook
INNER JOIN linkedin
ON facebook.name = linkedin.name
LEFT JOIN
or RIGHT JOIN
LEFT JOIN is decidedly the more common,
and you can make any RIGHT JOIN a
LEFT JOIN just by flipping the table
orderingNULL values will be inserted for the
secondary table columns if no match is foundSELECT *
FROM facebook
LEFT JOIN linkedin
ON facebook.name = linkedin.name
FULL OUTER JOIN will do
what you want
LEFT JOIN followed by
a RIGHT JOIN with the existing tableNULL valuesSELECT *
FROM facebook
FULL OUTER JOIN linkedin
ON facebook.name = linkedin.name
CROSS JOIN will return a table of all
of these possibilitiesSELECT *
FROM facebook
CROSS JOIN linkedin


Unique first names of students who have submitted any assignment?

Student ID and name of the assignment for all perfect scores?

How many students have submitted nothing? Do any assignments have no submissions?

What is the most common number of days to submit an assignment late?

If every student had turned in every assignment, how many total points would need to be graded/scored?