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

  • SEARCH
  • Home
  • 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 8736477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:18:36+00:00 2026-06-13T10:18:36+00:00

I’m using SQLite. I need an help for an easy issue. Here’s my three

  • 0

I’m using SQLite.
I need an help for an easy issue.
Here’s my three tables:

--------------
problem
--------------
id (primary key)
question_id (foreign key)

--------------
question
--------------
id (primary key)
answer_id (foreign key)

--------------
answer
--------------
id (primary key)

I would like to get ALL problems that have at least N answers in every question of a problem. I’ll give you an example:

-------
problem
id 
1
2


-------
question 
id   problem_id
1    1
2    1
3    1
4    2

-------
answer
id   question_id
1    1
2    1
3    1
4    2
5    2
6    3
7    4
8    4

If n=2, my result should be problem_id=2.

I’ve tried this:

   select distinct question.problem_id 
   from answer, question
   where answer.question_id = question.id
   group by answer.question_id
   having count(*) >= 2

but it doesn’t work because it gets problems with at least one question with at least 2 answers. All questions must satisfy that condition.

Any problems?

  • 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-13T10:18:37+00:00Added an answer on June 13, 2026 at 10:18 am

    Here’s my go at the issue in T-SQL:

    declare @problem table(id bigint not null primary key clustered)
    declare @question table(id bigint not null primary key clustered, problem_id bigint)
    declare @answer table(id bigint not null primary key clustered, question_id bigint)
    
    declare @n int = 2
    
    insert @problem
          select 1 
    union select 2
    
    insert @question
          select 1, 1 
    union select 2, 1
    union select 3, 1
    union select 4, 2
    
    insert @answer 
          select 1, 1 
    union select 2, 1
    union select 3, 1
    union select 4, 2
    union select 5, 2
    union select 6, 3
    union select 7, 4
    union select 8, 4
    
    select p.id --, p.name, p.description, p.etc
    from @problem p
    where @n >= ALL --http://msdn.microsoft.com/en-us/library/ms178543.aspx
    (
        select COUNT(a.id) 
        from @question q
        left outer join @answer a
            on q.id = a.question_id
        where p.id = q.problem_id
        group by q.id
    )
    

    NB: the table schema differs slightly from the question as the schema in the question doesn’t match the example data.

    ALTERNATIVE

    (based on @RichardTheKiwi’s answer with the inner SQL moved to a temp table)

    declare @tempTable table (pid bigint, qid bigint, aidCount bigint)
    
    insert @tempTable
    select q.problem_id, q.id, count(a.id) answercount
    from @question q
    left join @answer a on a.question_id = q.id
    group by q.problem_id, q.id
    
    select pid
    from @tempTable
    group by pid 
    having min(aidCount) >= @n 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have thousands of HTML files to process using Groovy/Java and I need to
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
In my XML file chapters tag has more chapter tag.i need to display chapters
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.