sql – Generating select statement with joins from table information – Education Career Blog

I’ve got a bunch of classes that describe database schema: Table,Field,ForeignKey.
Tables have ForeignKeys list and Fields list.

Now I would like to generate SELECT statement with all the joins that are described in ForeignKey instances.

The question is: is order of tables relevant for the query time? Another words – do I have to care or is it done automatically for me by the db engine?

,

is order of tables relevant for the query time? Another words – do I have to care or is it done automatically for me by the db engine?

To the optimizer, no — it doesn’t matter.

For sake of readability and maintainance, you might want to consider laying the FROM and JOIN clauses out in a manner that reads well. If only dealing with INNER joins, there’s no issue but OUTER JOINS I generally define after the FROM clause and use LEFT JOIN syntax exclusively. But that’s a matter of style & taste…

Leave a Comment