Support Subquery Exists
See original GitHub issue![image](https://user-images.githubusercontent.com/5905201/197430447-86614808-caf1-4f44-9a31-12f4b2ffb687.png)
A function like below code should be implemented in jdsl.
think about what kind of appearance is suitable for jdsl.
โ korean ํ์ฌ kotlin-jdsl ์ CriteriaBuilder.exists ๋ฉ์๋๋ฅผ ์ง์ํ์ง ์์ต๋๋ค. ์ด ๋ฉ์๋์ ๊ตฌํ์ด ํ์ํฉ๋๋ค.
์๋ ์ฝ๋์ ๊ฐ์ ๊ธฐ๋ฅ์ด jdsl์ ๊ตฌํ ๋์ด์ผ ํฉ๋๋ค.
์ด๋ค ๋ชจ์ต์ด jdsl ์ ์ ํฉํ์ง ๊ฐ์ด ๊ณ ๋ฏผํด๋ณด์์ผ๋ฉด ํฉ๋๋ค.
CriteriaBuilder builder = entityManager.getCriteriaBuilder();
CriteriaQuery<Post> query = builder.createQuery(Post.class);
Root<Post> p = query.from(Post.class);
ParameterExpression<Integer> minScore = builder.parameter(Integer.class);
Subquery<Integer> subQuery = query.subquery(Integer.class);
Root<PostComment> pc = subQuery.from(PostComment.class);
subQuery
.select(builder.literal(1))
.where(
builder.equal(pc.get(PostComment_.POST), p),
builder.gt(pc.get(PostComment_.SCORE), minScore)
);
query.where(builder.exists(subQuery));
List<Post> posts = entityManager.createQuery(query)
.setParameter(minScore, 10)
.getResultList();
generated SQL
SELECT
p.id AS id1_0_,
p.title AS title2_0_
FROM post p
WHERE EXISTS (
SELECT 1
FROM post_comment pc
WHERE
pc.post_id=p.id AND
pc.score > ?
)
ORDER BY p.id
Issue Analytics
- State:
- Created a year ago
- Comments:9 (6 by maintainers)
Top Results From Across the Web
SQL EXISTS Operator - W3Schools
The EXISTS operator is used to test for the existence of any record in a subquery. The EXISTS operator returns TRUE if the...
Read more >SQL: EXISTS Condition - TechOnTheNet
The SQL EXISTS condition is used in combination with a subquery and is considered to be met, if the subquery returns at least...
Read more >SQL EXISTS operator - w3resource
The EXISTS checks the existence of a result of a Subquery. The EXISTS subquery tests whether a subquery fetches at least one row....
Read more >Subqueries and EXISTS - MariaDB Knowledge Base
Subqueries using the EXISTS keyword will return true if the subquery returns any rows. Conversely, subqueries using NOT EXISTS will return true only...
Read more >Using EXISTS and NOT EXISTS with correlated subqueries
EXISTS and NOT EXISTS are used with a subquery in WHERE clause to examine if the result the subquery returns is TRUE or...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@kihwankim @cj848 2.0.7.RELEASE is released
@cj848
where(exists(subquery))
ํํ๊ฐ ๋ฑ ์ข์ ๊ฒ ๊ฐ์ต๋๋ค. ๐โ english
where(exists(subquery))
is the best form.