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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:49:54+00:00 2026-06-01T16:49:54+00:00

The following code fetches data if the SubjectB column from Table 2 matches the

  • 0

The following code fetches data if the SubjectB column from Table 2 matches the Subject A column from Table 1.

SELECT
UID
FROM
Table1
WHERE EXISTS (
    SELECT 1
    FROM Table2
    WHERE SubjectB = SubjectA
)

I want to add an additional condition after the closed parentheses:

AND another_column_from_table1 > 10

But the sytax does not seem valid. What is the correct way to have a query with WHERE EXISTS … AND conditions?

  • 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-01T16:49:56+00:00Added an answer on June 1, 2026 at 4:49 pm

    Given your initial query, you should be able to write:

    SELECT UID
      FROM Table1
     WHERE EXISTS (SELECT 1
                     FROM Table2
                    WHERE SubjectB = SubjectA
                  )
       AND another_column_from_table1 > 10;
    

    There shouldn’t be a syntax error from simply adding the condition to the end of the query. From the comments, it seems that this is syntactically accepted, but generates no output. The obvious technique to debug this is:

    SELECT UID, another_column_from_table1
      FROM Table1
     WHERE EXISTS (SELECT 1
                     FROM Table2
                    WHERE SubjectB = SubjectA
                  )
    

    This will show you the values in the column; presumably, since the result set is empty when you add the extra filter condition, the values in the second column of this select will all be less than 10 (or null).

    If there’s a one-to-one relationship between entries in Table1 and Table2, then you can use a JOIN instead:

    SELECT t1.UID
      FROM Table1 AS t1
      JOIN Table2 AS t2 ON t2.SubjectB = t1.SubjectA
     WHERE t1.another_column_from_table1 > 10;
    

    If there could be several rows in Table2 for each row in Table1, then you would need to add DISTINCT:

    SELECT DISTINCT t1.UID
      FROM Table1 AS t1
      JOIN Table2 AS t2 ON t2.SubjectB = t1.SubjectA
     WHERE t1.another_column_from_table1 > 10;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that fetches some data from a php script. I'm
I have some code that fetches some data from the database, database codepage is
Consider the following two methods, written in pseudo code, that fetches a complex data
I have the following code to fetch the data from URL, store it in
Following code iterates through many data-rows, calcs some score per row and then sorts
Following code is from a sample of playframework-2.0: /** * Display the dashboard. */
Following code is to save image took from camera into photo album. if ([mediaType
This is related to Classic ASP code. A page fetches data for a particular
I am designing an application that fetches data from a sqlite database on the
I am wondering if someone could clarify the following from Apples Core Data documentation:

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.