Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between these three MySQL queries?

Tags:

sql

join

mysql

SELECT title,name FROM Lessons,Users WHERE Lessons.author = Users.email;

and

SELECT title,name FROM Lessons JOIN Users ON Lessons.author = Users.email;

and

SELECT title,name FROM Lessons INNER JOIN Users ON Lessons.author = Users.email;

Lessons has a column named author indexed as a foreign key to a Users.email. title is a column in Lessons and name is a column in Users

like image 308
Mark Avatar asked Jan 26 '12 18:01

Mark


People also ask

What is the difference between any and all in MySQL?

ANY and ALL operate on subqueries that return multiple values. ANY returns true if any of the subquery values meet the condition. ALL returns true if all of the subquery values meet the condition.

What are the differences between MySQL and SQL?

What is the major difference between MySQL and SQL? SQL is a query programming language for managing RDBMS. In contrast, MySQL is an RDBMS (Relational Database Management System) that employs SQL. So, the major difference between the two is that MySQL is software, but SQL is a database language.

What is the difference between SQL and query?

A query is an operation on the database. A sql file is a list of queries to run.


1 Answers

There is no difference between the three statements, they all are, either implicit or explicit, INNER JOINs

  1. The first statement is using the implicit old join syntax. While this is still supported, using explicit joins is both more readable and maintainable. Don't use old style joins.

  2. The second statement is using an explicit join without specifying the type of join. By default, this is an INNER JOIN

  3. The third statement is also an explicit join and avoids any ambiguities. This is by far the most recommended way of writing joins.

like image 150
Lieven Keersmaekers Avatar answered Sep 28 '22 16:09

Lieven Keersmaekers