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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:07:55+00:00 2026-05-18T09:07:55+00:00

I have two tables table1 and table2 . Both tables have the same structure.

  • 0

I have two tables table1 and table2. Both tables have the same structure. They have 4 columns (x1, y1, z1 and w1 in the first table and x2, y2, z2, w2, in the second table).

I want to extract values of the first column of the second table (x2). The procedure is as following:

  1. Extract all rows from the second table for which y2=y0 and w2=w0.
  2. For every extracted row take values of the first three columns (x_i, y_i and z_i).
  3. From the first table extract all rows for which x1==x_i and y1==y_i and z1==z_i (I know in advance that one or zero rows will be extracted).
  4. For the extracted row (if there is one) check the value in the column w1. If it is not equal to w0 add x_i to the list. If there are no rows extracted from the first table, also add x_i to the list.
  5. Repeat this procedure for all rows extracted from the second table on the step 1.

In the end I want to have a unique list of values from the x2 (no duplicates).

My question is if the described procedure can be performed by one command.

ADDED

w0 and y0 are known and fixed (just some fixed values).

  • 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-18T09:07:56+00:00Added an answer on May 18, 2026 at 9:07 am

    You will need an idColumn on table1 that will only have not null values. It will be used to test that the left join (which represents condition number 3.) actually produced any results or not. If any of the table’s other columns does not allow null values, it can be used instead of idColumn.

    select distinct t2.x2
    from table2 as t2
    left join table1 as t1 on t1.x1 = t2.x2 and t1.y1 = t2.y2 and t1.z1 = t2.z2
    where t2.y2 = y0 and t2.w2 = w0 and ( t1.w1  w0 or t1.idColumn is null )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes generated by LINQ2SQL both from the same table so they
I have two tables which have the exact same structure. Both tables can store
I have two Tables say Table-A and Table-B having same table structure (means number
I have two tables that have the exact same structure. Table MasterList Acct_id(9) Name
I have two databases at two different places, both databases are same with table
I have two tables: orders and orders_items. Both sharing the field orderID. I want
I have two tables in different databases on the same database server. Both the
I have data in two tables that I want to query from. Each table
I have table1 and table2 that have the same schema... and I want to
I have two tables that have the same structure; one contains permanaent data, and

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.