public static String buildSearchAnimeByName(String approximateName, SearchFilter filter) {
        resetClause();

        select.append("A.*");
        from.append("\"Anime_\" A");

        if (filter.hasSeason()) {
            from.append("\"Season\" S")
                    .append("\"AnimeSeason\" AS_");
            where.append("A.id = AS_.anime_id")
                    .append("AS_.season_id = S.id");
        }

        if (filter.hasGenre()) {
            from.append("\"Genre\" G");
            where.append("A.id = G.anime_id");
        }

        if (approximateName != null) {
            where.append("(UPPER(english_title) LIKE UPPER('%" + approximateName + "%') OR " +
                    " UPPER(romaji_title) LIKE UPPER('%" + approximateName + "%'))");
        }

        if (filter.hasMustHaveGenre()) {
            String mustHaveGenre = filter.getMustHaveGenreInSql();
            where.append("G.tag IN " + mustHaveGenre);
            groupBy.append("A.id");
            having.append("COUNT(G.tag) >= " + filter.getNumberOfMustHaveGenre());
        }

        if (filter.hasStartSeason()) {
            String startSeason = filter.getStartSeason();
            String startYear = extractYear(startSeason);
            where.append("S.year >= " + startYear);
        }

        if (filter.hasEndSeason()) {
            String endSeason = filter.getEndSeason();
            String endYear = extractYear(endSeason);
            where.append("S.year <= " + endYear);
        }

        String query = buildQuery();
        if (filter.hasExcludedGenre()) {
            String excludedGenre = filter.getExcludedGenreInSql();
            String subQuery = selectExcludedGenreAnime(excludedGenre);
            query += "EXCEPT\n" + subQuery;
        }


        if (filter.hasStartSeason()) {
            String startSeason = filter.getStartSeason();
            String year = extractYear(startSeason);
            String aSeason = extractSeasonInYear(startSeason);
            String allSeasonFromThis = retrieveSeasonInStartYear(aSeason);
            String subQuery = selectAnimeInSeason(year, allSeasonFromThis);
            query += "EXCEPT\n" + subQuery;
        }

        if (filter.hasEndSeason()) {
            String endSeason = filter.getEndSeason();
            String year = extractYear(endSeason);
            String aSeason = extractSeasonInYear(endSeason);
            String allSeasonToThis = retrieveSeasonInEndYear(aSeason);
            String subQuery = selectAnimeInSeason(year, allSeasonToThis);
            query += "EXCEPT\n" + subQuery;
        }

        return query;
    }