Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right join with a where clause

Tags:

sql

join

I found a query like this in code:

 SELECT *
   FROM a
        RIGHT JOIN b ON a.id = b.id
  WHERE a.id = b.id

Is it basically the same as an inner join on a.id = b.id?

like image 335
Victor Avatar asked May 26 '14 15:05

Victor


People also ask

Can you use a WHERE clause in a join?

To use the WHERE clause to perform the same join as you perform using the INNER JOIN syntax, enter both the join condition and the additional selection condition in the WHERE clause. The tables to be joined are listed in the FROM clause, separated by commas.

Does WHERE clause go before or after join?

If you move the same filter to the WHERE clause, you will notice that the filter happens after the tables are joined.

Can I use WHERE clause in outer join?

Introduction. Although an ON clause is required for each operation in an outer join in a FROM clause, an outer join can itself also include a WHERE clause. Any restriction in the WHERE clause is applied only to the table that is the final result of the outer join.

Can we use WHERE clause with natural join?

This example uses natural join syntax to merge specified columns from the Customers and Sales tables. The result set is filtered with a WHERE clause.


1 Answers

Yes, this is basically the same as an inner join.

The where clause will fail when there are no matches, because the value a.id will be NULL.

like image 179
Gordon Linoff Avatar answered Sep 21 '22 21:09

Gordon Linoff