gilbert189 — 11/21/2025, 2:58:06 AM

this week’s database system practice post test: making the most spaghetti SQL queries:

-- no intersect =(
select distinct (
    select name
    from Lecturers
    where id=C1.lecturer_id
    limit 1
) as name
from Courses as C1
where
    exists(
        select 1
        from Courses as C2
        where
            C2.lecturer_id=C1.lecturer_id
            and C2.semester='Odd'
    )
    and exists(
        select 1
        from Courses as C2
        where
            C2.lecturer_id=C1.lecturer_id
            and C2.semester='Even'
    )
;

(we’re learning set operations and subqueries, so joins are not allowed)

♥ 3 ↩ 0 💬 2 comments

comments

zaydmohammed2:

this might not be neccesary, but do you know basic set theory

11/24/2025, 7:04:24 AM
gilbert189:

yes but I can’t use intersect, the version of MySQL that the computers at the lab has doesn’t have it

11/24/2025, 3:02:49 PM