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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:39:17+00:00 2026-05-27T13:39:17+00:00

Table 1 uses joining Table2 for a many to many relationship with Table 3.

  • 0

Table 1 uses joining Table2 for a many to many relationship with Table 3.

Table1

ID

Table2

Table1ID
Table3ID

Table3

ID
SomeData

I want a query that will return only 1 instance of a row from Table1 for a search for multiple Table2.ID’s

Table1:
ID

1

2

3

4

Table 2

1 1

1 2

2 2

2 3

Table3

1 “foo”

2 “bar”

3 “whizz”

4 “bang”

Now I can do a join with a subquery

SELECT * FROM Table1
 WHERE ID in (

SELECT DISTINCT(T1.ID)
FROM Table1 T1 LEFT OUTER JOIN Table2
ON T1.ID = T2.Table1ID
WHERE T2.Table3ID in (1,2)

)

where 1 and 2 are the values I’m searching for.

Now I want to wrap this up in a view so I can query something like:

Select ID, {other stuff from T1} from vwGetData

where Value in (1,2)

Is this possible? hope I made it clear enough

TIA!

  • 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-27T13:39:18+00:00Added an answer on May 27, 2026 at 1:39 pm

    If you need some values from Table1 your query should look like this:

    select T1.*
    from Table1 as T1
    where T1.ID in (select T2.Table1ID      
                    from Table2 as T2
                    where T2.Table2ID in (1, 2))
    

    There is no way to create a view of that and allow you to add in the filter on (1, 2) as a where clause to the query of the view.

    Your sample query against the view only retrieves the ID column so to get that information you don’t need to involve Table1 in the query.

    select distinct T2.Table1ID as ID
    from Table2 as T2
    where T2.Table2ID in (1, 2)
    

    You could create a view of that (without the distinct part) but that would not make much sense at all would it?

    create view v_Table2
    as
    select Table1ID, Table2ID
    from Table2
    

    Used like this:

    select distinct T2.Table1ID as ID
    from v_Table2 as T2
    where T2.Table2ID in (1, 2)
    

    The view does not really add any value.

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

Sidebar

Related Questions

Assume a table that uses a natural key and has a number of existing
I want to index a computed column in my database table which uses a
Im trying to return a SimpleQuery list that queries a single table and uses
I have content management system application that uses a polymorphic tree table as the
I have a web page that uses jquery ajax to grab the table markup
I have an Nhibernate hbm that maps a many to many relationship. For database
following on from my other post... I have a table that uses two fields
I have a table which uses a background image that is 1500px wide. Since
I have an iphone app that uses table view as the interface. Each time
I have a table that uses a SET datatype for one of the fields,

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.