-- Consulta 0: Devuelve todos los juegos y sus archivos asociados
SELECT DISTINCT
    e.title,
    l.name,
    r.release_year,
    d.file_link,
    f.text
FROM
    (
        (
            (
                (
                    (
                        (
                            publishers p
                            INNER JOIN entries e ON p.entry_id = e.id
                        )
                        INNER JOIN labels l ON p.label_id = l.id
                    )
                    INNER JOIN genretypes g ON e.genretype_id = g.id
                )
                INNER JOIN downloads d ON e.id = d.entry_id
            )
            INNER JOIN filetypes f ON d.filetype_id = f.id
        )
        INNER JOIN releases r ON e.id = r.entry_id
        AND p.release_seq = r.release_seq
    )
WHERE
    (
        e.availabletype_id = 'A'
        OR e.availabletype_id = 'D'
    )
    AND (
        f.text <> 'Remote link'
        AND f.text <> '?'
    )
    AND r.release_seq = 0
    AND (
        g.text like '%Game:%'
        AND g.text not like 'Casual%'
    )
ORDER BY
    e.title;

-- Consulta 1: Filtra más la consulta anterior
SELECT DISTINCT
    e.title,
    l.name,
    r.release_year,
    d.file_link,
    f.text
FROM
    (
        (
            (
                (
                    (
                        (
                            publishers p
                            INNER JOIN entries e ON p.entry_id = e.id
                        )
                        INNER JOIN labels l ON p.label_id = l.id
                    )
                    INNER JOIN genretypes g ON e.genretype_id = g.id
                )
                INNER JOIN downloads d ON e.id = d.entry_id
            )
            INNER JOIN filetypes f ON d.filetype_id = f.id
        )
        INNER JOIN releases r ON e.id = r.entry_id
        AND p.release_seq = r.release_seq
    )
WHERE
    (
        e.availabletype_id = 'A'
        OR e.availabletype_id = 'D'
    )
    AND (
        f.text <> 'Remote link'
        AND f.text <> '?'
    )
    AND r.release_seq = 0
    AND l.name like 'ZOSYA%'
    AND (
        g.text like '%Game:%'
        AND g.text not like 'Casual%'
    )
ORDER BY
    e.title;

-- Consulta 2: Devuelve juegos y solo archivos de cinta, disco o pokes
SELECT DISTINCT
    e.title,
    l.name,
    r.release_year,
    d.file_link,
    f.text
FROM
    (
        (
            (
                (
                    (
                        (
                            publishers p
                            INNER JOIN entries e ON p.entry_id = e.id
                        ) INNER JOIN labels l ON p.label_id = l.id
                    ) INNER JOIN genretypes g ON e.genretype_id = g.id
                ) INNER JOIN downloads d ON e.id = d.entry_id
            ) INNER JOIN filetypes f ON d.filetype_id = f.id
        ) INNER JOIN releases r ON e.id = r.entry_id
        AND p.release_seq = r.release_seq
    )
WHERE
    (
        e.availabletype_id = 'A'
        OR e.availabletype_id = 'D'
    )
    AND (
        f.text IN (
            'Tape image',
            'Disk image',
            'Snapshot image',
            'POK pokes file'
        )
    )
    AND r.release_seq = 0
    AND (
        g.text like '%Game:%'
        AND g.text not like 'Casual%'
    )
ORDER BY
    e.title;

-- Consulta 3: ZXNEXT - Devuelve juegos y solo archivos de cinta o pokes
SELECT DISTINCT
    e.title,
    l.name,
    r.release_year,
    d.file_link,
    f.text
FROM
    (
        (
            (
                (
                    (
                        (
                            publishers p
                            INNER JOIN entries e ON p.entry_id = e.id
                        ) INNER JOIN labels l ON p.label_id = l.id
                    ) INNER JOIN genretypes g ON e.genretype_id = g.id
                ) INNER JOIN downloads d ON e.id = d.entry_id
            ) INNER JOIN filetypes f ON d.filetype_id = f.id
        ) INNER JOIN releases r ON e.id = r.entry_id
        AND p.release_seq = r.release_seq
    )
WHERE
    (
        e.availabletype_id = 'A'
        OR e.availabletype_id = 'D'
    )
    AND (
        f.text IN (
            'Tape image',
            'Snapshot image',
            'POK pokes file'
        )
    )
    AND r.release_seq = 0
    AND (
        g.text like '%Game:%'
        AND g.text not like 'Casual%'
    )
ORDER BY
    e.title;