left and right join

Vineet S 265 Reputation points
2024-06-23T11:34:41.0833333+00:00

Hi,

table 1

User's image

Table 2

User's image

select A.* from table1a LEFT join table2 b on a.col1=b.col1

output:

User's image

which is correct

but on right join

User's image

it shows above results how to calculate this join and how it will react on NULL and blank

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,164 questions
Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,589 questions
0 comments No comments
{count} votes

Accepted answer
  1. Erland Sommarskog 104.7K Reputation points MVP
    2024-06-23T11:56:27.08+00:00

    If the left join gives you the correct result, use a left join.

    A RIGHT JOIN B is the same B LEFT JOIN A. Personally, I never use RIGHT JOIN. It gives me a headache every time I see it.

    Also, keep in mind that when joining two tables, no matter the join type, the join column(s) should be a unique key in at least in one of the tables. If they are non-unique in both tables, you will get a row explosion. That is, if there are three rows in one table and four in the other, all with the same key value, the join will produce twelve rows.


0 additional answers

Sort by: Most helpful