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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:03:18+00:00 2026-06-05T08:03:18+00:00

While trying an outer join query I noticed that changing one condition from the

  • 0

While trying an outer join query I noticed that changing one condition from the where clause to the join clause changes the result. That surprised me but I simplified the tables and the query as below and now I think I understand but I would like to hear a solid explanation.

create table t0 (id int, b int);
create table t1 (id int, b int);
insert into t0 (id, b) values (1, 10), (2, 10);
insert into t1 (id, b) values (1, 2);

select t0.id, t0.b
from t0
left outer join t1 on 
    t0.id = t1.id
where
    t0.b = 10
    and
    t1.b = 2
;
 id | b  
----+----
  1 | 10
(1 row)

Now I move one of the conditions from the where to the join clause:

select t0.id, t0.b
from t0
left outer join t1 on 
    t0.id = t1.id
    and
    t1.b = 2
where 
    t0.b = 10
;
 id | b  
----+----
  1 | 10
  2 | 10
(2 rows)

Do you know how to write a straight reasoning?

  • 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-05T08:03:24+00:00Added an answer on June 5, 2026 at 8:03 am

    The on condition of an outer join only determines if the join succeeds. If the join fails, the joined columns are filled with null.

    On the other hand, a where clause filters entire rows out of the result set.

    To make this more clear, addd t1.b to the result set. With t1.b = 2 as a where condition, you get:

    t0.id   t0.b   t1.id   t1.b
    1       10     1       2
    

    versus t1.b = 2 as an on condition::

    t0.id   t0.b   t1.id   t1.b
    1       10     1       2
    2       10     NULL    NULL
    

    You can see why the where clause filters the second row out: null = 2 is not true.

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

Sidebar

Related Questions

I am trying to query data from two tables into one tables using OUTER
I'm trying to create a python server that will serve calls from outer source
While trying to process a JSON response with GSON (the output is from the
While trying to verify to myself, that C# Equals for IEnumerables is a reference
I am trying to do a LEFT JOIN in Hibernate Query Language, in MySQL
I am trying to change my sub-query in to a join where it selects
While trying to generate classes from a xsd, i got this error: java.lang.IllegalArgumentException: Illegal
I have an SQL query that I built for a tool a while ago
I'm trying to parse a never-ending xml stream that looks like this: <outer> <foo>footext</foo>
While trying to compute the width of an hidden element I found that jquery.width()

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.