efficient way to JOIN in SQL -


i have join 2 tables: articles , sales, not data of articles, need last load.

is there difference between 2 ways? there faster/efficient way? , more important, why?

1)

select * sales s inner join articles on s.article_id = a.article_id , a.load_date = (select max(load_date) articles) 

2)

select * sales s inner join (     select *     articles     load_date = (select max(load_date) articles) ) on s.article_id = a.article_id 

most dbmses support windowed aggregate functions , rank might more efficient (and easier write if you're used it):

select *  (    select *,      rank()  -- max date gets rank #1      on (partition a.article_id            order a.load_date desc) rn    sales s    inner join articles    on s.article_id = a.article_id  ) dt wher rn = 1 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -