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 985969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:14:48+00:00 2026-05-16T05:14:48+00:00

System: Windows7, Access 2003, .mdb file, C# language, VS 2010 I’m doing queries with

  • 0

System: Windows7, Access 2003, .mdb file, C# language, VS 2010

I’m doing queries with OleDbCommand, so I write the complete sql query in a string.


Table Survey  (Id)  
Table Questions  (Id,IdSurvey)  
Table Answers (Id,IdQuestion)  

the tables are simplified to show only relevant data

Assume 1 survey has 1..n questions
Assume 1 question has 0..n answers

I want to select only the surveys that have the answers 1 and/or 2 for the Question3, how do I do that?

Current (and poor) solution:

SELECT surv.Name FROM Survey surv WHERE 
(1 IN (SELECT answ.Number FROM Answers answ, Questions quest 
WHERE quest.Id = 3 AND quest.IdSurvey = surv.Id) 
AND/OR 
(2 IN (SELECT answ.Number FROM Answers answ, Questions quest
WHERE quest.Id = 3 AND quest.IdSurvey = surv.Id)))

This looks like crap, so I would appreciate help.

Thanks in advance.


EDIT

Better solution i came up with:

For 1 OR 2, the solutions given here are enough (for very simple logical expressions). Thanks guys

For 1 AND 2, i have created another solution, looks kinda good i think (again, for very simple logical expressions)

SELECT surv.Name FROM Survey surv WHERE EXISTS
(SELECT COUNT(*) FROM Answers answ, Questions quest 
WHERE quest.Id = 3 AND answ.Number IN (1,2) HAVING COUNT(*) > 1)

The “1” in the HAVING clause means that at least two lines are needed, and since the answers dont repeat for the same questions, this necesseraly means that at least the answers 1 AND 2 exists for the queried question.

Well, both the OR solution and the AND solution are bad when dealing with more complex logical expressions, like (1 AND (2 OR (4 AND (6 OR 7) ) ) ), truth is, its highly unlikely that such complexity will be needed, but i’d like to be safe. The ideal solution for me would be this:

SELECT surv.Name FROM Survey surv WHERE 
(1 IN (SELECT answ.Number FROM Answers answ, Questions quest 
WHERE quest.Id = 3 AND quest.IdSurvey = surv.Id) AS CANT_DO_THIS
AND/OR 
(2 IN CANT_DO_THIS) AND/OR 5 IN CANT_DO_THIS AND/OR 3 NOT IN CANT_DO_THIS)
  • 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-05-16T05:14:49+00:00Added an answer on May 16, 2026 at 5:14 am
    SELECT surv.Name FROM Survery surv
        INNER JOIN Questions quest ON surv.ID = quest.IDSurvey
        INNER JOIN Answers answ ON quest.ID = answ.IDQuestion
        WHERE quest.ID = 3 AND answ.Number IN (1, 2)
    

    This will return one line per survey (because you’re linking in only question ID 3 and the single answer to that question), and only for surveys where the answer to question 3 is 1 or 2.

    NOTE: It’s not clear to me how you join the Questions and Answer table in your data model, so I assumed that the Answers table has a foreign key back to Questions called IDQuestion.

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

Sidebar

Related Questions

CIFS is common internet file system, which is a protocol used to access windows
I'm trying to write a file system iterator as a simple Windows Application. I
I have a file on a Windows 2003 NTFS file system. It is called
Is there a way to access the windows registry system using coldfusion. Something like
I have an application that sporadically throws this exception: System.ObjectDisposedException: Cannot access a disposed
SQL Server 2000 on Windows Server 2003. I am trying to run a backup,
Question: Should I write my application to directly access a database Image Repository or
I want to access a remote windows system from my Mac system and work
I've added System.Windows and Microsoft.LightSwitch.Threading; to get access to the clipboard. When I run
i am trying to get the remote access from windows system to linux system

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.