joins

SELECT t.host, f.name
FROM targets t
INNER JOIN findings f ON f.target_id = t.id
WHERE t.severity = 'high'
ORDER BY f.name;

Output:

beta.local   header leak
beta.local   tls version

Why aliases

t and f keep the statement short They also force you to say which table each column belongs to That habit prevents the ambiguous column error later

INNER versus LEFT

INNER JOIN keeps rows that match on both sides LEFT JOIN keeps every row from the left table and fills the right side with nulls when nothing matches

Use LEFT when absence is information Use INNER when a row without a partner should disappear

The ON clause

ON describes the relationship Putting that condition in WHERE turns the join into a cross product filter The result can look the same and cost very differently

Next

Counting in 06 aggregates

Posted