sql - How records are being sorted while using join in psql? -


how records being sorted while using join in psql?

in cases seems sorted 1 of column otherwise, seems sorting order in maches our query after on . not sure how done. while using right , left join simply, nature of displaying records?

in general there no internal order records in sql table. postgres documentation on order by:

after query has produced output table (after select list has been processed) can optionally sorted. if sorting not chosen, rows returned in unspecified order. actual order in case depend on scan , join plan types , order on disk, must not relied on. particular output ordering can guaranteed if sort step explicitly chosen.

if want have order in result set need specify 1 using order by. example, if joining 2 tables a , b use:

select     a.col, a.col2, b.col3 a inner join b b     on a.col = b.col order     a.col2      -- or replace whatever column/logic want use 

even if there appears order current query, should not rely on it. adding more data, adding column, or doing vacuum cause "order" change.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -