2

So If I've asked the following question:

Write a SQL statement to find the list of customers who appointed a salesman for their jobs who gets a commission from the company is more than 12%

Tables: customer

customer_id  cust_name     city        grade       salesman_id
-----------  ------------  ----------  ----------  -----------
3002         Nick Rimando  New York    100         5001
3005         Graham Zusi   California  200         5002
3001         Brad Guzan    London      100         5005
3004         Fabian Johns  Paris       300         5006
3007         Brad Davis    New York    200         5001
3009         Geoff Camero  Berlin      100         5003
3008         Julian Green  London      300         5002
3003         Jozy Altidor  Moncow      200         5007

salesman

salesman_id  name        city        commission
-----------  ----------  ----------  ----------
5001         James Hoog  New York    0.15
5002         Nail Knite  Paris       0.13
5005         Pit Alex    London      0.11
5006         Mc Lyon     Paris       0.14
5003         Lauson Hen  San Jose    0.12
5007         Paul Adam   Rome        0.13

Is there any different between the following ways to do it? If so, What is the different? Because the end result is the same

If both are the same, why to use ever a INNER JOIN sentence? it seams more difficult to me that the first solution

select customer.cust_name, salesman.name, salesman.commission
from customer, salesman
where salesman.commission > 0.12 and customer.salesman_id = salesman.salesman_id

-

select customer.cust_name, salesman.name, salesman.commission
from customer INNER JOIN
     salesman
     ON customer.salesman_id = salesman.salesman_id
where salesman.commission > 0.12 

Thank you so much

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107
Martin D
  • 43
  • 2

3 Answers3

0

The "more difficult" solution is the one you're not used to. Most of the world uses INNER JOIN these days, so if you want to write code that will be more universally readable to other programmers, you should use INNER JOIN

Tab Alleman
  • 31,483
  • 7
  • 36
  • 52
0

You don't specify which database platform you're asking for, but for MS SQL Server at least the first form, an implicit join, is deprecated. For instance, see:

https://msdn.microsoft.com/en-us/library/dd172122(v=vs.100).aspx

https://sqlblog.org/2009/10/08/bad-habits-to-kick-using-old-style-joins

For me personally explicit joins are easier to write and read.

Also, because it is a deprecated syntax, the wise thing to do is to get used to the implicit joins now, since newer versions of SQL Server won't support the older syntax.

Aaron Bertrand
  • 272,866
  • 37
  • 466
  • 490
user2316154
  • 302
  • 2
  • 13
  • Here is the site I'm using to get some exercise and some learning and they way they are querying multiple tables without a JOIN: [Site](http://www.w3resource.com/sql-exercises/sql-exercises-quering-on-multiple-table.php) – Martin D Jun 06 '16 at 19:29
  • Any recommendation of a site where to practice SQL – Martin D Jun 06 '16 at 19:30
0

The result is the same because the queries are substantially the same as the difference is purely notational where the indication of the type of joins (inner join) in this care clearly makes explicit the kind of relationship that exists between the table.

The use of an explict relation is preferable .. and confor to the most use standard guidelines a sql raccomendation

ScaisEdge
  • 131,976
  • 10
  • 91
  • 107