Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

INNER JOIN Where Clause [duplicate]

Tags:

sql

sql-server

Is there a difference between doing something like

SELECT * 
FROM table1 INNER JOIN table2 ON table2.ObjectId = table1.table2ObjectId 
WHERE table2.Value = 'Foo'

vs

SELECT * 
FROM table1 INNER JOIN table2 
ON table2.ObjectId = table1.table2ObjectId AND table2.Value = 'Foo'
like image 421
Arizona1911 Avatar asked Aug 09 '13 18:08

Arizona1911


People also ask

Can inner join have duplicates?

The answer is yes, if there are any. If there are duplicate keys in the tables being joined.

Why inner join gives duplicate records?

Using an Incomplete ON Condition Unwanted rows in the result set may come from incomplete ON conditions. In some cases, you need to join tables by multiple columns. In these situations, if you use only one pair of columns, it results in duplicate rows.

Can we use inner join after WHERE clause?

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. This query returns the same output as the previous example.

How do you avoid duplicates in join?

Solution. Select column values in a specific order within rows to make rows with duplicate sets of values identical. Then you can use SELECT DISTINCT to remove duplicates. Alternatively, retrieve rows in such a way that near-duplicates are not even selected.


1 Answers

Not with an inner join. An outer join is where placement will make a difference.

like image 64
J.T. Avatar answered Oct 09 '22 15:10

J.T.