Questions tagged [right-join]

The RIGHT JOIN keyword will return all the rows from the right table, even if there are no matches in the left table.

SQL RIGHT JOIN ON returns the rows of INNER JOIN ON plus unmatched right table rows extended by NULLs. A consequence is that it returns all the rows from the right table at least once even if there are no matches in the left table. See examples here.

233 questions
237
votes
8 answers

Are "from Table1 left join Table2" and "from Table2 right join Table1" interchangeable?

For example, there are two tables: create table Table1 (id int, Name varchar (10)) create table Table2 (id int, Name varchar (10)) Table1 data as follows: Id Name ------------- 1 A 2 B Table2 data as…
Pankaj Agarwal
  • 11,191
  • 12
  • 43
  • 59
129
votes
3 answers

How to use mysql JOIN without ON condition?

Is it possible to write join query without ON statement? and how do these joins differ LEFT JOIN, RIGHT JOIN works.
Alexander T.
  • 1,401
  • 2
  • 9
  • 11
98
votes
4 answers

Difference between RIGHT & LEFT JOIN vs RIGHT & LEFT OUTER JOIN in SQL

What is the difference in results between: RIGHT JOIN and RIGHT OUTER JOIN LEFT JOIN and LEFT OUTER JOIN ? Can you please explain it through some examples?
Puru
  • 8,913
  • 26
  • 70
  • 91
78
votes
11 answers

When or why would you use a right outer join instead of left?

Wikipedia states: "In practice, explicit right outer joins are rarely used, since they can always be replaced with left outer joins and provide no additional functionality." Can anyone provide a situation where they have preferred to use the RIGHT…
DCookie
  • 42,630
  • 11
  • 83
  • 92
9
votes
3 answers

Database error - RIGHT and FULL OUTER JOINs are not currently supported

I was trying to RIGHT JOIN two tables using this query: SELECT Persons.firstname, company.lastname FROM Persons RIGHT JOIN company ON Persons.firstname=company.firstname; which comes with this error: RIGHT and FULL OUTER JOINs are not currently…
Amit
  • 556
  • 1
  • 7
  • 24
9
votes
2 answers

compare-object left or right side only

Quick Question Is there a better (i.e. more efficient / more concise) way to do this? compare-object $a $b | ?{$_.SideIndicator -eq '<='} Detail Compare-Object gives paramenters -excludeDifferent and -includeEqual to allow you to amend which…
JohnLBevan
  • 22,735
  • 13
  • 96
  • 178
9
votes
4 answers

Adding filter on the right side table on Left outer joins

On outer joins(lets take a left outer join in this case) how does adding a filter on the right side table work? SELECT s.id, i.name FROM Student s LEFT OUTER JOIN Student_Instructor i ON s.student_id=i.student_id AND i.name='John' I understand…
user624558
  • 559
  • 2
  • 8
  • 20
8
votes
3 answers

Performing a right join in django

Here are my models class Student: user = ForeignKey(User) department = IntegerField() semester = IntegerField() ... class Attendance: student = ForeignKey(Student) subject = ForeignKey(Subject) month = IntegerField() …
rjv
  • 6,058
  • 5
  • 27
  • 49
7
votes
3 answers

JPQL Right Join

After search I came to know that there is no Right Join in JPQL. I saw there is another way to achieve it using JPA bidirectional (not right join but using pojo object ) but one thing I noticed in console that it make many calls to database for eg…
pise
  • 849
  • 6
  • 24
  • 51
7
votes
5 answers

How to use left join like right join in Doctrine

In Doctrine there is no right join. You can use a left join like a right join but I can't figure it out for my example. I have an entity in Doctrine which has a one-to-one relationship with itself called "parent". I am trying to get all entities and…
Alex Mamut
  • 79
  • 1
  • 3
4
votes
2 answers

Want data added to the Query via Left Outer Joint to NOT repeat

I have a database structure (ER diagram below) that has three level of hierarchical data and the fourth level of optional data. If I write a query to get de-normalized data of three levels - level 1 to level 3 with sample data across three tables…
Moiz Tankiwala
  • 6,070
  • 7
  • 38
  • 51
4
votes
5 answers

why won't this query work properly?

my MasterSales table looks like this SalesDate | Category | Total ----------------------------- 1/1/2000 01 100 1/1/2000 02 110 1/2/2000 01 80 1/2/2000 03 20 and my Category table looks like…
dapidmini
  • 1,490
  • 2
  • 23
  • 46
3
votes
1 answer

How can I reverse the join order to get a right join with sqlalchemy using a subquery?

I'm trying to create the following (very much simplified) SQL statement with Flask-SQLAlchemy ORM SELECT TableA.attr FROM (SELECT DISTINCT TableB.a_id FROM TableB) AS TableB LEFT JOIN TableA ON TableA.id = TableB.a_id To achieve that I used the…
Midnight
  • 373
  • 2
  • 11
3
votes
1 answer

GROUP BY AND RIGHT JOINS IN DB2

Select p.prodCode, p.description, p.unit, SUM(sd.quantity) "Total quantity" FROM salesDetail sd RIGHT JOIN product p ON p.prodCode = sd.prodCode GROUP BY p.prodCode ORDER BY 4 DESC Help! My Script is not running. I need to…
AGK
  • 33
  • 4
3
votes
1 answer

Can't concatenate pandas dataframes with the same length?

This is weird. From the documentation I all ready read how to do concat and merge operations with pandas. Also I all ready know that concatenating to the right side can be done as follows: df = pd.concat([df1, df2], axis=1) The issue is that I…
tumbleweed
  • 4,624
  • 12
  • 50
  • 81
1
2 3
15 16