0

I have two queries:

$query = mysql_query("SELECT ord.orderID, customers.CustomerName,       
                      FROM ord, customers
                      WHERE customers.CustomerSalary=ord.orderID");

and

$query = mysql_query("SELECT ord.orderID, customers.CustomerName, 
                      FROM ord
                      INNER JOIN customers
                      ON customers.CustomerSalary=ord.orderID");

This queries return the same result. What is different between them.

hidd
  • 336
  • 3
  • 11
  • 4
    There is no difference, the first one is old school style and called implicit join and the 2nd one is more readable and widely used called explicit join. – Abhik Chakraborty Apr 01 '15 at 08:29

2 Answers2

0

Both are same. The first query is basically inner join on the back-end but the way you have written second query, you can use left join, right join etc with that query. Both will perform Cartesian Product on the back-end and filter out the results based on the check.

You will need to use the second query format in order to use left join, right join etc.

Another approach commonly used is known as nested queries. They are pretty faster than joins since there is no Cartesian product on the back-end.

hidd
  • 336
  • 3
  • 11
Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0
$query = mysql_query("SELECT ord.orderID, customers.CustomerName, 
                      FROM ord
                      INNER JOIN customers
                      ON customers.CustomerSalary=ord.orderID");

This query is optimised than the other one as Inner join get applied first and then where clause will be applied.

Other benifit I see that is you can change Inner Outer join.

Clean code.

Dnyanesh
  • 2,265
  • 3
  • 20
  • 17