Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between just using multiple froms and joins?

Tags:

sql

join

Say I have this query:

SELECT bugs.id, bug_color.name FROM bugs, bug_color
    WHERE bugs.id = 1 AND bugs.id = bug_color.id

Why would I use a join? And what would it look like?

like image 711
Thomaschaaf Avatar asked Sep 01 '25 10:09

Thomaschaaf


1 Answers

Joins are synticatic sugar, easier to read.

Your query would look like this with a join:

SELECT bugs.id, bug_color.name 
FROM bugs
INNER JOIN bug_color ON bugs.id = bug_color.id
WHERE bugs.id = 1

With more then two tables, joins help make a query more readable, by keeping conditions related to a table in one place.

like image 132
Andomar Avatar answered Sep 03 '25 02:09

Andomar