Skip to content

Commit c6ba408

Browse files
committed
correct query
1 parent 90ab13d commit c6ba408

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

src/main/java/ru/mystamps/web/dao/impl/JdbcCountryDao.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ public String findLastCreatedByUser(Integer userId) {
223223
return jdbcTemplate.queryForObject(
224224
findLastCreatedByUserSql,
225225
Collections.singletonMap("created_by", userId),
226-
String.class);
226+
String.class
227+
);
227228
} catch (EmptyResultDataAccessException ignored) {
228229
return null;
229230
}
@@ -237,10 +238,9 @@ public String findPopularCountryInCollection(Integer userId) {
237238
try {
238239
return jdbcTemplate.queryForObject(
239240
findPopularCountryInCollectionSql,
240-
Collections.<String, Object>emptyMap(),
241+
Collections.singletonMap("user_id", userId),
241242
String.class
242243
);
243-
244244
} catch (EmptyResultDataAccessException ignored) {
245245
return null;
246246
}

src/main/resources/sql/country_dao_queries.properties

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,12 @@ country.find_last_created_by_user = \
9292
LIMIT 1
9393

9494
country.find_popular_country_from_user_collection = \
95-
SELECT c.slug \
95+
SELECT co.slug \
9696
FROM collections c \
9797
JOIN collections_series cs ON c.id = cs.collection_id \
98-
WHERE c.user_id = :user_id \
99-
GROUP BY country_id \
100-
ORDER BY COUNT(*) DESC\
101-
LIMIT 1
98+
JOIN series s ON s.id = cs.series_id \
99+
JOIN countries co ON co.id = s.country_id \
100+
WHERE c.user_id = :user_id \
101+
GROUP BY co.id \
102+
ORDER BY COUNT(*) DESC \
103+
LIMIT 1

0 commit comments

Comments
 (0)