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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:35:37+00:00 2026-05-27T12:35:37+00:00

I have a query SELECT * FROM table1 WHERE documentId in ( –select items

  • 0

I have a query

SELECT * 
FROM table1
WHERE
documentId in
(
   --select items from a second table where a third column happens to be null
   select documentId from table2 t2 inner join table1 t1
   on t1.documentId = t2.documentId and t1.itemId = t2.ItemId
   WHERE t1.someOtherColumn is null
)
and itemId in
(
   --similar query as above, just selecting itemId now
   select itemId from table2 t2 inner join table1 t1
   on t1.documentId = t2.documentId and t1.itemId = t2.ItemId
   WHERE t1.someOtherColumn is null
)
order by 1

Given that table1 has composite PK = documentId + itemId, is this sufficient to select only values from table1 that are unique? My fear is that a situation may occur where documentId exists and itemId exists, but since they are not looked at together then incorrect selections can be made.

For example,

Let’s assume that there exists a value

documentId = 1 and itemId = 1.

Let’s assume there is no composite key

documentId = 1 and itemId = 1.

I do not want composite key

[documentId = 1 and itemId = 3]

to be included.

I also do not want composite key

[documentId = 2 and itemId = 1]

to be included.

If there were a composite key added later (it’s not there now)

[documentId = 1 and itemId = 1]

then it should be included.

  • 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-27T12:35:38+00:00Added an answer on May 27, 2026 at 12:35 pm

    This would do the same without having to use a join nor two INs

    SELECT *
    FROM table1
    WHERE exists
    (
        SELECT 1
        FROM table2
        WHERE someOtherColumn is null
            AND table1.documentId = table2.documentId
            AND table1.itemId = table2.ItemId
    )
    ORDER BY 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this query: select * from table1 r where r.x =
I have the following query: SELECT rowid FROM table1 ORDER BY RANDOM() LIMIT 1
I have a query like so : SELECT * FROM table WHERE premium =
I have the following query: select column_name, count(column_name) from table group by column_name having
Let say that we have the following query: SELECT DISTINCT COUNT(`users_id`) FROM `users_table`; this
I have a query like this: SELECT TABLE_NAME, COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM MY_DB.INFORMATION_SCHEMA.COLUMNS WHERE
i have sql query select * from Roles Join Users On Roles.Role=Users.RoleId it return
I have this query: SELECT * FROM sample INNER JOIN test ON sample.sample_number =
I have a query to select from another sub-query select. While the two queries
I have this SQL query: SELECT * FROM IMAGES WHERE IMAGENAME in ('IMG1', 'IMG2',

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.