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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:08:34+00:00 2026-06-03T05:08:34+00:00

I want to know the difference (visually) would be the best between the two

  • 0

I want to know the difference (visually) would be the best between the two following SELECT statements.

SELECT P.* and X.* 
FROM Table1 P
LEFT OUTER JOIN 
    Table2 X ON
    and  p.B=x.B
and  p.C=x.C
and  p.F=x.F
and  p.D=x.D 

WHERE X.F= 1 and X.E=4 

and

SELECT P.* and X.* 
FROM Table1 P
LEFT OUTER JOIN 
    (SELECT * FROM Table2 WHERE X.F= 1 and X.E =4) X
    and  p.B=x.B
and  p.C=x.C
and  p.F=x.F
and  p.D=x.D

They do not return the same number of rows. Lets say Table1 has 5000 rows and Table2 has 5000 rows also. The first select join statement returns ~40000 rows (specific to my query at work) and then when the where clause is applied, it returns about 2000 rows.

The second select join statement returns 5000 rows (original number). This is the number I want.

But I can’t seem to understand why this is happening. My knowledge and visuallizing joins is a bit weak.

Sample Data: Please change the name of the temp tables, they are the same. Also I couldn’t provide proper column names but have edited my code to indicate which columsn I want match
Here is TABLE1:

    SELECT * INTO #tmp_GridResults_1
FROM (
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'1' AS [E], N'2' AS [F] ) t;
SELECT [ID], [B], [C], [D], [E], [F]
FROM #tmp_GridResults_1

DROP TABLE #tmp_GridResults_1
GO

Here is Table2:
————— #tmp_GridResults_1 —————

SELECT * INTO #tmp_GridResults_1
FROM (
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'0' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'0' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'0' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'0' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'0' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'0' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'0' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'0' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'1' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'1' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'2' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'2' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'2' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'2' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'2' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'2' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'2' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'2' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'2' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'2' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'2' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'2' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'3' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'3' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'3' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'3' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'3' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'3' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'3' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'3' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'3' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'3' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'3' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'3' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'4' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'4' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'4' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'4' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'4' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'4' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'4' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'4' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'4' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'4' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'4' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'4' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'98' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'98' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'-1' AS [D], N'98' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'-1' AS [D], N'98' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'98' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'98' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'0' AS [D], N'98' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'0' AS [D], N'98' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'98' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'98' AS [E], N'1' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'1' AS [C], N'1' AS [D], N'98' AS [E], N'2' AS [F] UNION ALL
SELECT N'0' AS [ID], N'P' AS [B], N'2' AS [C], N'1' AS [D], N'98' AS [E], N'2' AS [F] ) t;
SELECT [ID], [B], [C], [D], [E], [F]
FROM #tmp_GridResults_1

DROP TABLE #tmp_GridResults_1
GO
  • 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-03T05:08:36+00:00Added an answer on June 3, 2026 at 5:08 am

    If you put filter criteria in the WHERE clause, and that criteria dictates conditions against the “outer” tables of a join, you effectively turn that outer join into an inner join. Filter criteria against an outer join table belongs in the join, not in the where.

    How many rows does this version yield?

    SELECT P.*, X.* 
    FROM Table1 P
    LEFT OUTER JOIN Table2 X
        on P.Id = X.id 
        and P.name = X.name 
        and P.age = X.age 
        AND X.bar = 1 
        and X.name ='value';
    

    Theoretically, this should yield >= the number of rows in your first statement, and = the number of rows in your second.

    If you want to compare this with your existing result, you can do:

    SELECT P.*, X.* 
    FROM Table1 P
    LEFT OUTER JOIN Table2 X
        on P.Id = X.id 
        and P.name = X.name 
        and P.age = X.age 
        AND X.bar = 1 
        and X.name ='value'
    EXCEPT
    SELECT P.* and X.*
    FROM Table1 P
    LEFT OUTER JOIN 
        (SELECT * FROM Table2 WHERE X.bar = 1 and X.name ='value') X
        on P.Id = X.id 
        and P.name = X.name 
        and P.age = X.age;
    

    If you get no results, they’re the same. You could also do it the opposite way:

    SELECT P.*, X.* 
    FROM Table1 P
    LEFT OUTER JOIN Table2 X
        on P.Id = X.id 
        and P.name = X.name 
        and P.age = X.age 
        AND X.bar = 1 
        and X.name ='value'
    INTERSECT
    SELECT P.* and X.*
    FROM Table1 P
    LEFT OUTER JOIN 
        (SELECT * FROM Table2 WHERE X.bar = 1 and X.name ='value') X
        on P.Id = X.id 
        and P.name = X.name 
        and P.age = X.age;
    

    If you get 5000 rows (or whatever the exact row count is for the latter query by itself), then the result sets are the same.

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

Sidebar

Related Questions

I want to know that difference between following two lines name1 = [[NSString stringWithUTF8String:(char
I want to know the difference between these two statements.... ch=getch(); ch=(*getch)(); both statements
I want to know the difference between these two statements. Is one 'better' than
I want to know what the difference is between alt= and name= Would it
I want to know what exactly is the difference between CLR & CLI? From
I want to know what the difference is between these two regular expressions, what
i want to know the time difference between two countries. There is ofcourse the
I just want to know what the difference between all the conditional statements in
I want to know the difference between the two flags BatteryManager.BATTERY_STATUS_DISCHARGING And BatteryManager.BATTERY_STATUS_NOT_CHARGING I
I want to know the difference between : $this->forward(module, action); And $this->redirect(module/action); My first

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.