0

hello I am learning SQL and want to know what is the best way to perform a JOIN operation with 2 or more tables, i tried this query:

SELECT  d.name, c.group, e.name as extra_name
FROM drinks d, combos c, extras e
WHERE d.id = c.drinks_id AND e.id = c.extras_id

This query works fine, this is a bad practice? or i must to use a INNER JOIN clause to do an join operation? thanks for your replies

maudev
  • 974
  • 1
  • 14
  • 32
  • good enuf for me thx @RaphaëlAlthaus – Drew Sep 22 '16 at 07:09
  • Maybe in the year 2000 it was very well done :p – Drew Sep 22 '16 at 07:11
  • It does the job, so, well done. Check here for the syntax and good explanation: http://www.w3schools.com/sql/sql_join_full.asp – Bert Verhees Sep 22 '16 at 07:16
  • Wow ! sorry for duplicating.. ok using an INNER JOIN clause is more fast? talking in terms of efficiency – maudev Sep 22 '16 at 07:19
  • You cannot say an inner join is more fast, what you use is a notation for an inner join, and a good SQL parser will use it like that. The only problem with your notation is that it is implicitly and possible not clear to others maintaining your code. – Bert Verhees Sep 22 '16 at 07:23
  • I say this because I want to know the difference when using left join , right join, outer join .. in the university i learned JOIN operations with the WHERE clause , now that I 'm working on development i need to know what is the difference using them in performance terms – maudev Sep 22 '16 at 07:30
  • You don't choose for a specific JOIN construct for performance reasons, but because you need that data. INNER JOIN on primary keys is always most fast, but when you need a RIGHT JOIN or FULL JOIN, this knowledge does not help you. Look at the w3schools-link I posted here, it explains the JOIN-types well. (look at the diagrams). In fact, it is quite easy to understand. – Bert Verhees Sep 22 '16 at 07:34
  • Ok ! thank u so much – maudev Sep 22 '16 at 07:36
  • you could experiment by trying some inner joins then comparing the query execution plans to CROSS JOINS where the criteria is moved to the WHERE clause. You might be surprised to often see identical query execution plans where the queries are effectively identical. on a LEFT JOIN, moving a condition from the ON section to the WHERE section can cause records that were selected to be excluded, if terms from the right table are NULL (in the ON part they could be NULL, but in the WHERE part that might ceaswe to be true) – Cato Sep 22 '16 at 10:22

0 Answers0