Skip to main content
 

And you thought your SQL sucked..

Go on over to the New York Times home page and view source. Drop your jaw at the HTML comments that reveal their gnarly SQL they use to generate their home page.

Each three article section has the SQL used to generate it in a comment above it. The funny thing is that the SQL is longer than the results.

  select oid 
    from assetrelationtree
   where otype='NYT_Article' and nparentid in 
         (select nid from assetrelationtree where nparentid=0 and oid in
            (select id from collection where id in 
              (select distinct oid from assetrelationtree 
                where nparentid=(select nid from assetrelationtree 
                                  where oid=1004547 and nparentid=0) and
                                        otype='Collection') and 
                                    subtype='NYT_Article')) and 
                      ncode <= '20060407' and 
                      oid not in (1125004343548,1125004284421,1125004335857,
                                  1125004327602,1125004279763,1125004286523,
                                  1125004276389,1125004338045,1125004296004) 
     order by ncode DESC,nrank ASC