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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:11:47+00:00 2026-06-01T13:11:47+00:00

Create two tables with some ids overlapping. create table outer_table ( id integer, overlap_in

  • 0

Create two tables with some ids overlapping.

create table outer_table (
    id integer,
    overlap_in smallint default 0
);
create table inner_table (
    inner_id integer
);

Next, populate them with ids, some common.

insert into outer_table(id) values 0, 1, 2, 3, 4, 5, 6, 7, 8, 9;
insert into inner_table(inner_id) values 0, 1, 2;

Next, update the overlap indicator. BUT, by mistake, you type in the wrong column name, you write just “id” instead of “inner_id”, and you decide not to use an alias.

update outer_table o
set o.overlap_in = 1
where o.id in (select id from inner_table);

The result:

  1. No SQL errors
  2. It update overlap_in field to 1 in all rows in outer_table

How is this even normal? Any explanations why db2 allows this?

Note: DB2 Version:

>db2level
DB21085I  Instance "....." uses "64" bits and DB2 code release "SQL09075"
with level identifier "08060107".
Informational tokens are "DB2 v9.7.0.5", "...", "IP23285", and Fix Pack
"5".
  • 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-01T13:11:48+00:00Added an answer on June 1, 2026 at 1:11 pm

    This is normal, expected behavior. As in most every programming language, identifiers are resolved this way in SQL. If an identifier does not exist in the innermost scope, name resolution works outward. If there is no column named “id” in the innermost scope, the column name is resolved outside that scope. Here, “id” is resolved as o.id. You should always use table prefixes!

    Suppose you had written

    where exists (
      select * from inner_table
      where inner_table.inner_id = id
    )
    

    You would certainly want the identifier “id” to be resolved as o.id, just like it is in your example. It would be silly if within a subquery, you could not refer to columns from other tables in the query.

    That said, it would also be nice if some SQL implementations could do sanity checks that flagged queries like this, because if there is only one column mentioned in a subquery with a FROM clause, it usually should be a column from the table in the subquery. If not, it’s typically a typo (but still a legal query).

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

Sidebar

Related Questions

I have two tables: codes_tags and popular_tags. codes_tags CREATE TABLE `codes_tags` ( `code_id` int(11)
I have two tables: entitytype and project . Here are the create table statements:
I have two tables A and B as defined bellow. create table A (
So I have two tables structured like so: CREATE TABLE #nodes(node int NOT NULL);
Alright so here are my two tables. CREATE TABLE [cards] ( [id] TEXT PRIMARY
I have two tables CREATE TABLE table1 (id int primary key auto_increment,....); CREATE TABLE
I have two tables : create table CurrentDay ( ID int identity primary key,
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
In my dbsql file, I have two CREATE TABLES the first works and the
How to create a relation between two tables using PHPMyAdmin?

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.