Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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,             customers.customers_firstname,             customers.customers_lastname         FROM `DM_Server`.`Jobs`         INNER JOIN `DM_Server`.servers ON servers.ServerID = Jobs.Jobs_ServerID         JOIN `cpod_live`.`digital_inventory` ON digital_inventory.jobname = Jobs.Jobs_Name         JOIN `cpod_live`.`products` ON products.products_pdfupload = CONCAT(digital_inventory.jobname, ".pdf")         JOIN `cpod_live`.`customers` ON customers.customers_id = products.cID         ORDER BY `DM_Server`.`Jobs`.Jobs_StartTime DESC LIMIT 50 

it runs fine until I make them LEFT JOINs. I thought that by not specifying a type of join it was assumed to be a LEFT JOIN. Is this not the case?

like image 494
Webnet Avatar asked Mar 19 '12 12:03

Webnet


People also ask

What is difference between join and left join in MySQL?

LEFT (OUTER) JOIN : Returns all records from the left table, and the matched records from the right table. RIGHT (OUTER) JOIN : Returns all records from the right table, and the matched records from the left table. FULL (OUTER) JOIN : Returns all records when there is a match in either left or right table.

When to Use join vs LEFT join?

A join combines the set of two tables only. A left join is used when a user wants to extract the left table's data only. Left join not only combines the left table's rows but also the rows that match alongside the right table.

Is join in MySQL left join?

The MySQL LEFT JOIN joins two tables and fetches rows based on a condition, which is matching in both the tables and the unmatched rows will also be available from the table written before the JOIN clause.

Which is faster Left join or join?

A LEFT JOIN is absolutely not faster than an INNER JOIN . In fact, it's slower; by definition, an outer join ( LEFT JOIN or RIGHT JOIN ) has to do all the work of an INNER JOIN plus the extra work of null-extending the results.


1 Answers

I thought that by not specifying a type of join it was assumed to be a LEFT JOIN. Is this not the case?

No, the default join is an INNER JOIN.

Here is a visual explanation of SQL joins.

Inner join

enter image description here

Left join

enter image description here

like image 194
Mark Byers Avatar answered Sep 30 '22 11:09

Mark Byers