Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why select from multiple tables without join

Tags:

sql

When joining tables one can traditionally use the SQL89 way of joining like

SELECT * FROM t1, t2 WHERE t1.id = t2.t1_id;

But since the SQL92 standard, we can now join using the JOIN syntax

SELECT * FROM t1 JOIN t2 on t1.id=t2.t1_id;

Is there any reason why someone would SELECT from multiple tables without joining? Now, I know people concatenate data using UNION, but that is not what I'm talking about.

Is the reason we add tables with commas in the FROM clause strictly for backwards compatibility? Or are there any realistic scenarios which using the old syntax would be impossible by doing just joins?

like image 456
Kirk Backus Avatar asked Jul 12 '13 15:07

Kirk Backus


People also ask

Can I select from multiple tables without join?

Yes, Tables Can Be Joined Without the JOIN Keyword.

Why is it better to have multiple separate tables?

Storing all data in one single table will be confusing, may have security issues and there will be duplication in recording. Multiple table helps in recording the data in more organized manner when there are multiple users. The data can be stored as per the category and there will be less chances of duplication.

What are the disadvantages of join?

Disadvantages Of Joins: Disadvantage of using joins includes that they are not as easy to read as subqueries. More joins in a query means the database server has to do more work, which means that it is more time consuming process to retrieve data.

What is the necessity of joins?

The SQL Joins clause is used to combine records from two or more tables in a database. A JOIN is a means for combining fields from two tables by using values common to each.


1 Answers

I'll admit that muscle memory kicks in and sometimes I use the 89 way before thinking. But I do prefer the 92 method because it keeps the WHERE clause cleaner. The only conditions in the WHERE clause are the ones relevant to your business case while the criteria that exist simply to define relationships are neatly in JOIN clauses.

like image 112
dazedandconfused Avatar answered Oct 10 '22 09:10

dazedandconfused