0

Beginner Q. Learning SQL and was doing some online training exercises and came across this solution to create a summary from two tables:

SELECT salesman.name AS "Salesman",
customer.cust_name, customer.city 
FROM salesman,customer 
WHERE salesman.city=customer.city;

I find this confusing because I would have expected to do a JOIN when pulling from two different tables. My Udemy training never gave examples of FROM statements for multiple tables at the same time : )

Is this an alternate way of doing a basic JOIN? Or is there some reason JOIN does something this can't?

Thanks

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Chris
  • 9
  • 1
  • 2
    Implicit joins were replaced with explicit join syntax in the ANSI-92 SQL standards. Nearly 30 years later, the ANSI-89 implicit syntax is still oddly being used, and more oddly being taught, but most practitioners caution against using it. There's a lot of good discussion [here](https://stackoverflow.com/questions/44917/explicit-vs-implicit-sql-joins). – Eric Brandt May 21 '20 at 17:54
  • 1
    The comma is just an archaic way of writing the `JOIN`. Best to forget you ever saw it. – Gordon Linoff May 21 '20 at 17:58
  • Does this answer your question? [INNER JOIN ON vs WHERE clause](https://stackoverflow.com/questions/1018822/inner-join-on-vs-where-clause) – philipxy May 21 '20 at 18:34
  • Comma is cross join with lower precedence than keyword joins. https://stackoverflow.com/a/25957600/3404097 – philipxy May 21 '20 at 18:35

1 Answers1

1

You can do with join as follow, this is called explicit join, and you should always try to use this as it provides more readability in query.

SELECT 
  s.name as Salesman,
  c.cust_name, 
  c.city 
FROM salesman s
join customer c
on s.city=c.city;

when you use multiple table with where statement then it is called implicit join as you have used in your query. performance wise both should be the same.

zealous
  • 7,336
  • 4
  • 16
  • 36
  • Thank you! I wasn't familiar with the concept of explicit vs implicit joins. Sounds like it's ok (and perhaps better for readability) to just stick to explicit joins in general. – Chris May 21 '20 at 17:46