0

I am doing some relational algebra exercizes. On a teacher slide I saw a thing that makes me think that there can be an error. I think, the third JOIN, should be

JOIN 'Farmacia' as F
ON 'D'.'idCF' = 'F'.'idFì

instead of

JOIN 'Farmacia' as F
ON 'F'.'idFì = 'D'.'idCF'

Using this last command you will join Farmacia on itself, isn't it?

The slide question says:

Which pharmacy does sell drug X of phramaceutic company Y?

enter image description here

Germano Massullo
  • 2,572
  • 11
  • 40
  • 55

1 Answers1

3

The order of the columns in the ON part of the statement doesn't influence how the JOIN itself is done.

This:

SELECT t1.columnA, t2.columnB
FROM Table1 t1
   JOIN Table2 t2 ON t1.ID = t2.ID

will yield the same results as this:

SELECT t1.columnA, t2.columnB
FROM Table1 t1
   JOIN Table2 t2 ON t2.ID = t1.ID

The self-join you described would have been something like this:

SELECT t1.columnA, t2.columnB
FROM Table1 t1
   JOIN Table1 t2 ON t1.managerID = t2.employeeID
SchmitzIT
  • 9,227
  • 9
  • 65
  • 92
  • Sorry, just another question: what about the order of joins? – Germano Massullo Nov 17 '13 at 15:56
  • 1
    Do you mean the order of the tables in the JOINS? When writing queries, you typically add the tables in the order they relate to one another. If you have a chain of related tables, I do believe it's good practice using the chain in proper order. Some query tools might throw errors if the JOIN you are writing relies on a not-yet-referenced table. However, when you actually run the query, I'd like to think the engine would figure it all out. – SchmitzIT Nov 17 '13 at 16:45