Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8108259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:03:23+00:00 2026-06-06T01:03:23+00:00

Here is my simplified database: user_post – id – post_id (FK) post – id

  • 0

Here is my simplified database:

user_post
- id
- post_id (FK)

post
- id
- link_id (FK)

link
- id

I’ve a list of user_post and I wanna get for each of them the link they are linked to.

Currently, I’m doin it like this:

SELECT userPost.post.link FROM UserPost userPost WHERE userPost IN (:userPosts)

Works great, but maybe later, I’ll get a huge number of user_post, so there’ll be a lot of values within the IN clause (100 < x < 5000+).

Is IN limited? Is there any other way to do it? Before, I was doin it like this:

for (UserPost userPost : user.getUserPosts()) {
    Link link = userPost.getPost().getLink();
    //
}

But the solution above takes really a lot of time to get executed, so I’m lookin for a more optimized one.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T01:03:25+00:00Added an answer on June 6, 2026 at 1:03 am

    Yes, the IN clause is limited:

    The number of values in the IN list is only limited by the
    max_allowed_packet value.

    In Oracle, the limit is set to 1000 elements.

    Instead of selecting user posts, and then iterating through them to get their link or issuing another query to get them, you could load the links in the same query as the user posts:

    select userPost from UserPost userPost
    left join fetch userPost.post post
    left join fetch post.link link;
    

    This query will load eveything at once, and iterating theough the user posts and getting their link using userPost.getPost().getLink() won’t trigger any additional query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just getting into SQL stored queries right now... anyway, here's my database schema (simplified
I want to list all users with their corropsonding user class. Here are simplified
Here is a simplified version of my database model. I have two tables: Image,
I'm trying to optimize database queries for a Django app. Here's a simplified example:
Here is simplified version of my requirement I have a java class say Processor
I've got 3 tables that are something like this (simplified here ofc): users user_id
I look at example of dropdown menu here . Here is simplified jsfiddle example.
I am implementing a protocol library. Here a simplified description. The main thread within
Here is a simplified version of what I have (not working): prog.h: ... const
Here is a simplified version of the code I use. I need to rewrite

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.