Questions tagged [inner-join]

A database operation that combines the values of 2 tables based on a condition, or relationship, that exists between those tables.

An inner join is the most common join operation used in applications and can be regarded as the default join-type. Inner join creates a new result table by combining column values of two tables (A and B) based upon the join-predicate. The query compares each row of A with each row of B to find all pairs of rows which satisfy the join-predicate.

When the join-predicate is satisfied, column values for each matched pair of rows of A and B are combined into a result row. The result of the join can be defined as the outcome of first taking the Cartesian product (or Cross join) of all records in the tables (combining every record in table A with every record in table B) then returning all records which satisfy the join predicate.

Actual SQL implementations normally use other approaches like a hash join or a sort-merge join where possible, since computing the Cartesian product is very inefficient.

enter image description here


Resources :

6652 questions
5190
votes
28 answers

What is the difference between "INNER JOIN" and "OUTER JOIN"?

Also, how do LEFT OUTER JOIN, RIGHT OUTER JOIN, and FULL OUTER JOIN fit in?
Chris de Vries
  • 56,777
  • 5
  • 32
  • 27
2143
votes
2 answers

What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?

What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN in MySQL?
Lion King
  • 32,851
  • 25
  • 81
  • 143
1715
votes
14 answers

How can I delete using INNER JOIN with SQL Server?

I want to delete using INNER JOIN in SQL Server 2008. But I get this error: Msg 156, Level 15, State 1, Line 15 Incorrect syntax near the keyword 'INNER'. My code: DELETE FROM WorkRecord2 INNER JOIN Employee ON…
nettoon493
  • 17,733
  • 7
  • 30
  • 45
1391
votes
6 answers

Difference between JOIN and INNER JOIN

Both these joins will give me the same results: SELECT * FROM table JOIN otherTable ON table.ID = otherTable.FK vs SELECT * FROM table INNER JOIN otherTable ON table.ID = otherTable.FK Is there any difference between the statements in performance…
driis
  • 161,458
  • 45
  • 265
  • 341
1105
votes
12 answers

INNER JOIN ON vs WHERE clause

For simplicity, assume all relevant fields are NOT NULL. You can do: SELECT table1.this, table2.that, table2.somethingelse FROM table1, table2 WHERE table1.foreignkey = table2.primarykey AND (some other conditions) Or else: SELECT …
JCCyC
  • 16,140
  • 11
  • 48
  • 75
434
votes
2 answers

SQL Server - inner join when updating

I have the below query which does not work. What am I doing wrong? Is this even possible? UPDATE ProductReviews AS R INNER JOIN products AS P ON R.pid = P.id SET R.status = '0' WHERE R.id = '17190' AND P.shopkeeper = '89137'
LeeTee
  • 6,401
  • 16
  • 79
  • 139
380
votes
12 answers

SQL Inner-join with 3 tables?

I'm trying to join 3 tables in a view; here is the situation: I have a table that contains information of students who are applying to live on this College Campus. I have another table that lists the Hall Preferences (3 of them) for each Student.…
Bob Sanders
  • 4,317
  • 4
  • 18
  • 11
365
votes
15 answers

Update statement with inner join on Oracle

I have a query which works fine in MySQL, but when I run it on Oracle I get the following error: SQL Error: ORA-00933: SQL command not properly ended 00933. 00000 - "SQL command not properly ended" The query is: UPDATE table1 INNER JOIN table2…
user169743
  • 4,067
  • 5
  • 19
  • 14
161
votes
12 answers

MySQL INNER JOIN select only one row from second table

I have a users table and a payments table, for each user, those of which have payments, may have multiple associated payments in the payments table. I would like to select all users who have payments, but only select their latest payment. I'm trying…
Wasim
  • 4,953
  • 10
  • 52
  • 87
142
votes
3 answers

SQL DELETE with INNER JOIN

There are 2 tables, spawnlist and npc, and I need to delete data from spawnlsit. npc_templateid = n.idTemplate is the only thing that "connect" the tables. I have tried this script but it doesn't work. I have tried this: DELETE s FROM spawnlist…
JoinOG
  • 1,513
  • 3
  • 11
  • 9
134
votes
3 answers

Is having an 'OR' in an INNER JOIN condition a bad idea?

In trying to improve the speed of an immensely slow query (several minutes on two tables with only ~50,000 rows each, on SQL Server 2008 if it matters), I narrowed down the problem to an OR in my inner join, as in: SELECT mt.ID, mt.ParentID,…
ladenedge
  • 13,197
  • 11
  • 60
  • 117
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
89
votes
2 answers

Why does Pandas inner join give ValueError: len(left_on) must equal the number of levels in the index of "right"?

I'm trying to inner join DataFrame A to DataFrame B and am running into an error. Here's my join statement: merged = DataFrameA.join(DataFrameB, on=['Code','Date']) And here's the error: ValueError: len(left_on) must equal the number of levels in…
Ian Joyce
  • 1,039
  • 1
  • 7
  • 12
85
votes
10 answers

SQL Inner join more than two tables

I can currently query the join of two tables on the equality of a foreign/primary key in the following way. $result = mysql_query("SELECT * FROM `table1` INNER JOIN `table2` ON…
Ben Pearce
  • 6,884
  • 18
  • 70
  • 127
79
votes
4 answers

Difference in MySQL JOIN vs LEFT JOIN

I have this cross-database query... SELECT `DM_Server`.`Jobs`.*, `DM_Server`.servers.Description AS server, digital_inventory.params, products.products_id, products.products_pdfupload, …
Ben
  • 60,438
  • 111
  • 314
  • 488
1
2 3
99 100