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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:05:15+00:00 2026-05-23T16:05:15+00:00

Let there are 2 tables. To query the rows, which have the same IDs,

  • 0

Let there are 2 tables. To query the rows, which have the same IDs, you have to do this:

SELECT * FROM Table1 A, Table2 B WHERE A.id = B.id

Now let the tables be merged into one global table, with an added ex-table column. So, query

SELECT * FROM Table1

now looks like:

SELECT * FROM GlobalTable WHERE tableId = 1

But how the first query should look now?

SELECT * FROM Table1 A, Table2 B WHERE A.id = B.id

?

  • 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-23T16:05:16+00:00Added an answer on May 23, 2026 at 4:05 pm

    One table should store one entity. There is no such thing as a “one true lookup table” or “global table”. Nor should you consider an EAV. This question assumes all your tables have the same layout…

    However, I look forward to more rep later when it doesn’t work properly so…

    You should use explicit JOINs to separate filter and join conditions

    Select *
    from
       GlobalTable A
       JOIN
       GlobalTable B ON A.id = B.id
    WHERE
        A.tableId = 1 AND B.tableId = 2
    

    If you need to do an OUTER JOIN, then you can write this

    Select *
    from
       (SELECT * FROM GlobalTable WHERE tableId = 1) A
       LEFT JOIN
       (SELECT * FROM GlobalTable WHERE tableId = 2) B ON A.id = B.id
    

    I’d suggest using an indexed view though to persist “tableA” and “tableB” as separate objects to avoid this continual filtering. Or don’t merge them…

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

Sidebar

Related Questions

I have several hosts from which i want to do the same query. So
Let's say there is this table which stores the number of visitors for each
I have three tables, which are each 1:n. An entry in table1 has n
I have a dataset from a complex query which I've selected into a temp
Ive got a problem with a MySQL query. Let's say, we have two tables:
Let's say you have three tables named Item, Event, and Seat, constructed as such:
There is a table in a databse, let's call this table Document. This table
Let's say I have DatabaseA with TableA, which has these fields: Id, Name. In
I'm using Hibernate to retrieve the number of rows for a specific query. Let's
This is a SQL design question. First, the setup. I have three tables: A,

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.