[{"data":1,"prerenderedAt":2399},["Reactive",2],{"blog-overcoming-soql-limits":3},{"_path":4,"_dir":5,"_draft":6,"_partial":6,"_locale":7,"title":8,"description":9,"date":10,"author":11,"tags":14,"image":18,"body":19,"_type":2394,"_id":2395,"_source":2396,"_file":2397,"_extension":2398},"/blog/overcoming-soql-limits","blog",false,"","Overcoming the limits of SOQL","Salesforce Object Query Language (SOQL) has it's limits. Here are a few examples where you can use SQL to overcome those limits.","2026-03-22",{"name":12,"title":13},"Joe Fusaro","Founder, Datachef",[15,16,17],"soql","salesforce","sql","/datachef.png",{"type":20,"children":21,"toc":2387},"root",[22,38,43,164,184,191,231,235,240,245,262,453,458,463,948,953,958,970,989,1001,2018,2023,2028,2040,2045,2050,2347,2350,2358,2381],{"type":23,"tag":24,"props":25,"children":26},"element","p",{},[27,30,36],{"type":28,"value":29},"text","If you've spent time significant time in Salesforce, you've likely used ",{"type":23,"tag":31,"props":32,"children":33},"strong",{},[34],{"type":28,"value":35},"Salesforce Object Query Language",{"type":28,"value":37}," - or \"SOQL\", Salesforce's proprietary \"flavor\" of SQL.",{"type":23,"tag":24,"props":39,"children":40},{},[41],{"type":28,"value":42},"And if you've used SOQL for a while, chances are you've encountered one or more of it's limitations, which include:",{"type":23,"tag":44,"props":45,"children":46},"ul",{},[47,58,83,100,131,154],{"type":23,"tag":48,"props":49,"children":50},"li",{},[51,56],{"type":23,"tag":31,"props":52,"children":53},{},[54],{"type":28,"value":55},"No arbitrary JOINs.",{"type":28,"value":57}," You can traverse object relationships, but you can't freely join any two objects the way you can in SQL.",{"type":23,"tag":48,"props":59,"children":60},{},[61,81],{"type":23,"tag":31,"props":62,"children":63},{},[64,66,72,74,79],{"type":28,"value":65},"No ",{"type":23,"tag":67,"props":68,"children":69},"code",{"className":7},[70],{"type":28,"value":71},"UNION",{"type":28,"value":73}," or ",{"type":23,"tag":67,"props":75,"children":76},{"className":7},[77],{"type":28,"value":78},"UNION ALL",{"type":28,"value":80},".",{"type":28,"value":82}," You can't combine results from two separate queries into one result set.",{"type":23,"tag":48,"props":84,"children":85},{},[86,91,93,98],{"type":23,"tag":31,"props":87,"children":88},{},[89],{"type":28,"value":90},"No CTEs (Common Table Expressions).",{"type":28,"value":92}," You can't use ",{"type":23,"tag":67,"props":94,"children":95},{"className":7},[96],{"type":28,"value":97},"WITH",{"type":28,"value":99}," clauses to break complex logic into readable steps.",{"type":23,"tag":48,"props":101,"children":102},{},[103,108,110,115,117,122,124,129],{"type":23,"tag":31,"props":104,"children":105},{},[106],{"type":28,"value":107},"No window functions.",{"type":28,"value":109}," Things like ",{"type":23,"tag":67,"props":111,"children":112},{"className":7},[113],{"type":28,"value":114},"RANK()",{"type":28,"value":116},", ",{"type":23,"tag":67,"props":118,"children":119},{"className":7},[120],{"type":28,"value":121},"ROW_NUMBER()",{"type":28,"value":123},", or ",{"type":23,"tag":67,"props":125,"children":126},{"className":7},[127],{"type":28,"value":128},"LAG()",{"type":28,"value":130}," don't exist in SOQL.",{"type":23,"tag":48,"props":132,"children":133},{},[134,145,147,152],{"type":23,"tag":31,"props":135,"children":136},{},[137,138,143],{"type":28,"value":65},{"type":23,"tag":67,"props":139,"children":140},{"className":7},[141],{"type":28,"value":142},"CASE",{"type":28,"value":144}," statements.",{"type":28,"value":146}," Conditional logic in the ",{"type":23,"tag":67,"props":148,"children":149},{"className":7},[150],{"type":28,"value":151},"SELECT",{"type":28,"value":153}," clause isn't supported.",{"type":23,"tag":48,"props":155,"children":156},{},[157,162],{"type":23,"tag":31,"props":158,"children":159},{},[160],{"type":28,"value":161},"No cross-platform queries.",{"type":28,"value":163}," SOQL only sees Salesforce. It can't touch your Marketo data at the same time.",{"type":23,"tag":24,"props":165,"children":166},{},[167,169,175,177,182],{"type":28,"value":168},"Having your Salesforce data queryable with ",{"type":23,"tag":170,"props":171,"children":172},"em",{},[173],{"type":28,"value":174},"actual SQL",{"type":28,"value":176}," means you can overcome all of these restrictions. Here are a few simple examples of what you ",{"type":23,"tag":170,"props":178,"children":179},{},[180],{"type":28,"value":181},"can",{"type":28,"value":183}," do with SQL that you cannot do with SOQL.",{"type":23,"tag":185,"props":186,"children":188},"h2",{"id":187},"table-of-contents",[189],{"type":28,"value":190},"Table of Contents",{"type":23,"tag":44,"props":192,"children":193},{},[194,204,213,222],{"type":23,"tag":48,"props":195,"children":196},{},[197],{"type":23,"tag":198,"props":199,"children":201},"a",{"href":200},"#segmentation-with-regex",[202],{"type":28,"value":203},"Segmentation with Regex",{"type":23,"tag":48,"props":205,"children":206},{},[207],{"type":23,"tag":198,"props":208,"children":210},{"href":209},"#lead-and-contact-union",[211],{"type":28,"value":212},"Lead and Contact Union",{"type":23,"tag":48,"props":214,"children":215},{},[216],{"type":23,"tag":198,"props":217,"children":219},{"href":218},"#first-last-touch-with-window-functions",[220],{"type":28,"value":221},"First / Last Touch with Window Functions",{"type":23,"tag":48,"props":223,"children":224},{},[225],{"type":23,"tag":198,"props":226,"children":228},{"href":227},"#cross-platform-queries-eg-salesforce-marketo",[229],{"type":28,"value":230},"Cross-Platform Queries (e.g. Salesforce + Marketo)",{"type":23,"tag":232,"props":233,"children":234},"hr",{},[],{"type":23,"tag":185,"props":236,"children":238},{"id":237},"segmentation-with-regex",[239],{"type":28,"value":203},{"type":23,"tag":24,"props":241,"children":242},{},[243],{"type":28,"value":244},"Let's start with a simple one.",{"type":23,"tag":24,"props":246,"children":247},{},[248,250,254,256,260],{"type":28,"value":249},"SOQL won't let you add conditional logic inside a ",{"type":23,"tag":67,"props":251,"children":252},{"className":7},[253],{"type":28,"value":151},{"type":28,"value":255},". SQL does, with ",{"type":23,"tag":67,"props":257,"children":258},{"className":7},[259],{"type":28,"value":142},{"type":28,"value":261},". This is useful for on-the-fly segmentation or lead scoring without needing to create new fields in Salesforce.",{"type":23,"tag":263,"props":264,"children":267},"pre",{"className":265,"code":266,"language":17,"meta":7,"style":7},"language-sql shiki shiki-themes github-light github-dark","SELECT COUNT(DISTINCT id) AS records,\n       CASE \n          WHEN regexp_matches(title, '(?i)(VP|Chief|C-Suite|President)') THEN 'VP+'\n          WHEN regexp_matches(title, '(?i)(Director|Lead)') THEN 'Director'\n          ELSE 'Individual Contributor'\n       END AS title_segment\nFROM {{your_datachef_connection_id}}.lead\nGROUP BY title_segment\n",[268],{"type":23,"tag":67,"props":269,"children":270},{"__ignoreMap":7},[271,314,328,363,393,407,426,440],{"type":23,"tag":272,"props":273,"children":276},"span",{"class":274,"line":275},"line",1,[277,282,288,294,299,304,309],{"type":23,"tag":272,"props":278,"children":280},{"style":279},"--shiki-default:#D73A49;--shiki-dark:#F97583",[281],{"type":28,"value":151},{"type":23,"tag":272,"props":283,"children":285},{"style":284},"--shiki-default:#005CC5;--shiki-dark:#79B8FF",[286],{"type":28,"value":287}," COUNT",{"type":23,"tag":272,"props":289,"children":291},{"style":290},"--shiki-default:#24292E;--shiki-dark:#E1E4E8",[292],{"type":28,"value":293},"(",{"type":23,"tag":272,"props":295,"children":296},{"style":279},[297],{"type":28,"value":298},"DISTINCT",{"type":23,"tag":272,"props":300,"children":301},{"style":290},[302],{"type":28,"value":303}," id) ",{"type":23,"tag":272,"props":305,"children":306},{"style":279},[307],{"type":28,"value":308},"AS",{"type":23,"tag":272,"props":310,"children":311},{"style":290},[312],{"type":28,"value":313}," records,\n",{"type":23,"tag":272,"props":315,"children":317},{"class":274,"line":316},2,[318,323],{"type":23,"tag":272,"props":319,"children":320},{"style":279},[321],{"type":28,"value":322},"       CASE",{"type":23,"tag":272,"props":324,"children":325},{"style":290},[326],{"type":28,"value":327}," \n",{"type":23,"tag":272,"props":329,"children":331},{"class":274,"line":330},3,[332,337,342,348,353,358],{"type":23,"tag":272,"props":333,"children":334},{"style":279},[335],{"type":28,"value":336},"          WHEN",{"type":23,"tag":272,"props":338,"children":339},{"style":290},[340],{"type":28,"value":341}," regexp_matches(title, ",{"type":23,"tag":272,"props":343,"children":345},{"style":344},"--shiki-default:#032F62;--shiki-dark:#9ECBFF",[346],{"type":28,"value":347},"'(?i)(VP|Chief|C-Suite|President)'",{"type":23,"tag":272,"props":349,"children":350},{"style":290},[351],{"type":28,"value":352},") ",{"type":23,"tag":272,"props":354,"children":355},{"style":279},[356],{"type":28,"value":357},"THEN",{"type":23,"tag":272,"props":359,"children":360},{"style":344},[361],{"type":28,"value":362}," 'VP+'\n",{"type":23,"tag":272,"props":364,"children":366},{"class":274,"line":365},4,[367,371,375,380,384,388],{"type":23,"tag":272,"props":368,"children":369},{"style":279},[370],{"type":28,"value":336},{"type":23,"tag":272,"props":372,"children":373},{"style":290},[374],{"type":28,"value":341},{"type":23,"tag":272,"props":376,"children":377},{"style":344},[378],{"type":28,"value":379},"'(?i)(Director|Lead)'",{"type":23,"tag":272,"props":381,"children":382},{"style":290},[383],{"type":28,"value":352},{"type":23,"tag":272,"props":385,"children":386},{"style":279},[387],{"type":28,"value":357},{"type":23,"tag":272,"props":389,"children":390},{"style":344},[391],{"type":28,"value":392}," 'Director'\n",{"type":23,"tag":272,"props":394,"children":396},{"class":274,"line":395},5,[397,402],{"type":23,"tag":272,"props":398,"children":399},{"style":279},[400],{"type":28,"value":401},"          ELSE",{"type":23,"tag":272,"props":403,"children":404},{"style":344},[405],{"type":28,"value":406}," 'Individual Contributor'\n",{"type":23,"tag":272,"props":408,"children":410},{"class":274,"line":409},6,[411,416,421],{"type":23,"tag":272,"props":412,"children":413},{"style":279},[414],{"type":28,"value":415},"       END",{"type":23,"tag":272,"props":417,"children":418},{"style":279},[419],{"type":28,"value":420}," AS",{"type":23,"tag":272,"props":422,"children":423},{"style":290},[424],{"type":28,"value":425}," title_segment\n",{"type":23,"tag":272,"props":427,"children":429},{"class":274,"line":428},7,[430,435],{"type":23,"tag":272,"props":431,"children":432},{"style":279},[433],{"type":28,"value":434},"FROM",{"type":23,"tag":272,"props":436,"children":437},{"style":290},[438],{"type":28,"value":439}," {{your_datachef_connection_id}}.lead\n",{"type":23,"tag":272,"props":441,"children":443},{"class":274,"line":442},8,[444,449],{"type":23,"tag":272,"props":445,"children":446},{"style":279},[447],{"type":28,"value":448},"GROUP BY",{"type":23,"tag":272,"props":450,"children":451},{"style":290},[452],{"type":28,"value":425},{"type":23,"tag":185,"props":454,"children":456},{"id":455},"lead-and-contact-union",[457],{"type":28,"value":212},{"type":23,"tag":24,"props":459,"children":460},{},[461],{"type":28,"value":462},"Here, we combine unconverted Leads and Contacts into a single table, which is a core component of later examples.",{"type":23,"tag":263,"props":464,"children":466},{"className":265,"code":465,"language":17,"meta":7,"style":7},"  SELECT\n      co.id,\n      co.firstname,\n      co.lastname,\n      CASE \n          WHEN regexp_matches(title, '(?i)(VP|Chief|C-Suite|President)') THEN 'VP+'\n          WHEN regexp_matches(title, '(?i)(Director|Lead)') THEN 'Director'\n          ELSE 'Individual Contributor'\n      END AS title_segment,\n      co.email,\n      a.name company\n    FROM {{your_datachef_connection_id}}.contact co\n    JOIN {{your_datachef_connection_id}}.account a ON a.id = co.accountid\n    UNION\n    SELECT\n      id,\n      firstname,\n      lastname,\n      CASE \n          WHEN regexp_matches(title, '(?i)(VP|Chief|C-Suite|President)') THEN 'VP+'\n          WHEN regexp_matches(title, '(?i)(Director|Lead)') THEN 'Director'\n          ELSE 'Individual Contributor'\n      END AS title_segment,\n      email,\n      company\n    FROM {{your_datachef_connection_id}}.lead\n    WHERE NOT isdeleted AND NOT isconverted\n",[467],{"type":23,"tag":67,"props":468,"children":469},{"__ignoreMap":7},[470,478,500,520,540,552,579,606,617,635,656,679,693,744,753,762,771,780,789,801,829,857,869,885,894,903,915],{"type":23,"tag":272,"props":471,"children":472},{"class":274,"line":275},[473],{"type":23,"tag":272,"props":474,"children":475},{"style":279},[476],{"type":28,"value":477},"  SELECT\n",{"type":23,"tag":272,"props":479,"children":480},{"class":274,"line":316},[481,486,490,495],{"type":23,"tag":272,"props":482,"children":483},{"style":284},[484],{"type":28,"value":485},"      co",{"type":23,"tag":272,"props":487,"children":488},{"style":290},[489],{"type":28,"value":80},{"type":23,"tag":272,"props":491,"children":492},{"style":284},[493],{"type":28,"value":494},"id",{"type":23,"tag":272,"props":496,"children":497},{"style":290},[498],{"type":28,"value":499},",\n",{"type":23,"tag":272,"props":501,"children":502},{"class":274,"line":330},[503,507,511,516],{"type":23,"tag":272,"props":504,"children":505},{"style":284},[506],{"type":28,"value":485},{"type":23,"tag":272,"props":508,"children":509},{"style":290},[510],{"type":28,"value":80},{"type":23,"tag":272,"props":512,"children":513},{"style":284},[514],{"type":28,"value":515},"firstname",{"type":23,"tag":272,"props":517,"children":518},{"style":290},[519],{"type":28,"value":499},{"type":23,"tag":272,"props":521,"children":522},{"class":274,"line":365},[523,527,531,536],{"type":23,"tag":272,"props":524,"children":525},{"style":284},[526],{"type":28,"value":485},{"type":23,"tag":272,"props":528,"children":529},{"style":290},[530],{"type":28,"value":80},{"type":23,"tag":272,"props":532,"children":533},{"style":284},[534],{"type":28,"value":535},"lastname",{"type":23,"tag":272,"props":537,"children":538},{"style":290},[539],{"type":28,"value":499},{"type":23,"tag":272,"props":541,"children":542},{"class":274,"line":395},[543,548],{"type":23,"tag":272,"props":544,"children":545},{"style":279},[546],{"type":28,"value":547},"      CASE",{"type":23,"tag":272,"props":549,"children":550},{"style":290},[551],{"type":28,"value":327},{"type":23,"tag":272,"props":553,"children":554},{"class":274,"line":409},[555,559,563,567,571,575],{"type":23,"tag":272,"props":556,"children":557},{"style":279},[558],{"type":28,"value":336},{"type":23,"tag":272,"props":560,"children":561},{"style":290},[562],{"type":28,"value":341},{"type":23,"tag":272,"props":564,"children":565},{"style":344},[566],{"type":28,"value":347},{"type":23,"tag":272,"props":568,"children":569},{"style":290},[570],{"type":28,"value":352},{"type":23,"tag":272,"props":572,"children":573},{"style":279},[574],{"type":28,"value":357},{"type":23,"tag":272,"props":576,"children":577},{"style":344},[578],{"type":28,"value":362},{"type":23,"tag":272,"props":580,"children":581},{"class":274,"line":428},[582,586,590,594,598,602],{"type":23,"tag":272,"props":583,"children":584},{"style":279},[585],{"type":28,"value":336},{"type":23,"tag":272,"props":587,"children":588},{"style":290},[589],{"type":28,"value":341},{"type":23,"tag":272,"props":591,"children":592},{"style":344},[593],{"type":28,"value":379},{"type":23,"tag":272,"props":595,"children":596},{"style":290},[597],{"type":28,"value":352},{"type":23,"tag":272,"props":599,"children":600},{"style":279},[601],{"type":28,"value":357},{"type":23,"tag":272,"props":603,"children":604},{"style":344},[605],{"type":28,"value":392},{"type":23,"tag":272,"props":607,"children":608},{"class":274,"line":442},[609,613],{"type":23,"tag":272,"props":610,"children":611},{"style":279},[612],{"type":28,"value":401},{"type":23,"tag":272,"props":614,"children":615},{"style":344},[616],{"type":28,"value":406},{"type":23,"tag":272,"props":618,"children":620},{"class":274,"line":619},9,[621,626,630],{"type":23,"tag":272,"props":622,"children":623},{"style":279},[624],{"type":28,"value":625},"      END",{"type":23,"tag":272,"props":627,"children":628},{"style":279},[629],{"type":28,"value":420},{"type":23,"tag":272,"props":631,"children":632},{"style":290},[633],{"type":28,"value":634}," title_segment,\n",{"type":23,"tag":272,"props":636,"children":638},{"class":274,"line":637},10,[639,643,647,652],{"type":23,"tag":272,"props":640,"children":641},{"style":284},[642],{"type":28,"value":485},{"type":23,"tag":272,"props":644,"children":645},{"style":290},[646],{"type":28,"value":80},{"type":23,"tag":272,"props":648,"children":649},{"style":284},[650],{"type":28,"value":651},"email",{"type":23,"tag":272,"props":653,"children":654},{"style":290},[655],{"type":28,"value":499},{"type":23,"tag":272,"props":657,"children":659},{"class":274,"line":658},11,[660,665,669,674],{"type":23,"tag":272,"props":661,"children":662},{"style":284},[663],{"type":28,"value":664},"      a",{"type":23,"tag":272,"props":666,"children":667},{"style":290},[668],{"type":28,"value":80},{"type":23,"tag":272,"props":670,"children":671},{"style":284},[672],{"type":28,"value":673},"name",{"type":23,"tag":272,"props":675,"children":676},{"style":290},[677],{"type":28,"value":678}," company\n",{"type":23,"tag":272,"props":680,"children":682},{"class":274,"line":681},12,[683,688],{"type":23,"tag":272,"props":684,"children":685},{"style":279},[686],{"type":28,"value":687},"    FROM",{"type":23,"tag":272,"props":689,"children":690},{"style":290},[691],{"type":28,"value":692}," {{your_datachef_connection_id}}.contact co\n",{"type":23,"tag":272,"props":694,"children":696},{"class":274,"line":695},13,[697,702,707,712,717,721,725,730,735,739],{"type":23,"tag":272,"props":698,"children":699},{"style":279},[700],{"type":28,"value":701},"    JOIN",{"type":23,"tag":272,"props":703,"children":704},{"style":290},[705],{"type":28,"value":706}," {{your_datachef_connection_id}}.account a ",{"type":23,"tag":272,"props":708,"children":709},{"style":279},[710],{"type":28,"value":711},"ON",{"type":23,"tag":272,"props":713,"children":714},{"style":284},[715],{"type":28,"value":716}," a",{"type":23,"tag":272,"props":718,"children":719},{"style":290},[720],{"type":28,"value":80},{"type":23,"tag":272,"props":722,"children":723},{"style":284},[724],{"type":28,"value":494},{"type":23,"tag":272,"props":726,"children":727},{"style":279},[728],{"type":28,"value":729}," =",{"type":23,"tag":272,"props":731,"children":732},{"style":284},[733],{"type":28,"value":734}," co",{"type":23,"tag":272,"props":736,"children":737},{"style":290},[738],{"type":28,"value":80},{"type":23,"tag":272,"props":740,"children":741},{"style":284},[742],{"type":28,"value":743},"accountid\n",{"type":23,"tag":272,"props":745,"children":747},{"class":274,"line":746},14,[748],{"type":23,"tag":272,"props":749,"children":750},{"style":279},[751],{"type":28,"value":752},"    UNION\n",{"type":23,"tag":272,"props":754,"children":756},{"class":274,"line":755},15,[757],{"type":23,"tag":272,"props":758,"children":759},{"style":279},[760],{"type":28,"value":761},"    SELECT\n",{"type":23,"tag":272,"props":763,"children":765},{"class":274,"line":764},16,[766],{"type":23,"tag":272,"props":767,"children":768},{"style":290},[769],{"type":28,"value":770},"      id,\n",{"type":23,"tag":272,"props":772,"children":774},{"class":274,"line":773},17,[775],{"type":23,"tag":272,"props":776,"children":777},{"style":290},[778],{"type":28,"value":779},"      firstname,\n",{"type":23,"tag":272,"props":781,"children":783},{"class":274,"line":782},18,[784],{"type":23,"tag":272,"props":785,"children":786},{"style":290},[787],{"type":28,"value":788},"      lastname,\n",{"type":23,"tag":272,"props":790,"children":792},{"class":274,"line":791},19,[793,797],{"type":23,"tag":272,"props":794,"children":795},{"style":279},[796],{"type":28,"value":547},{"type":23,"tag":272,"props":798,"children":799},{"style":290},[800],{"type":28,"value":327},{"type":23,"tag":272,"props":802,"children":804},{"class":274,"line":803},20,[805,809,813,817,821,825],{"type":23,"tag":272,"props":806,"children":807},{"style":279},[808],{"type":28,"value":336},{"type":23,"tag":272,"props":810,"children":811},{"style":290},[812],{"type":28,"value":341},{"type":23,"tag":272,"props":814,"children":815},{"style":344},[816],{"type":28,"value":347},{"type":23,"tag":272,"props":818,"children":819},{"style":290},[820],{"type":28,"value":352},{"type":23,"tag":272,"props":822,"children":823},{"style":279},[824],{"type":28,"value":357},{"type":23,"tag":272,"props":826,"children":827},{"style":344},[828],{"type":28,"value":362},{"type":23,"tag":272,"props":830,"children":832},{"class":274,"line":831},21,[833,837,841,845,849,853],{"type":23,"tag":272,"props":834,"children":835},{"style":279},[836],{"type":28,"value":336},{"type":23,"tag":272,"props":838,"children":839},{"style":290},[840],{"type":28,"value":341},{"type":23,"tag":272,"props":842,"children":843},{"style":344},[844],{"type":28,"value":379},{"type":23,"tag":272,"props":846,"children":847},{"style":290},[848],{"type":28,"value":352},{"type":23,"tag":272,"props":850,"children":851},{"style":279},[852],{"type":28,"value":357},{"type":23,"tag":272,"props":854,"children":855},{"style":344},[856],{"type":28,"value":392},{"type":23,"tag":272,"props":858,"children":860},{"class":274,"line":859},22,[861,865],{"type":23,"tag":272,"props":862,"children":863},{"style":279},[864],{"type":28,"value":401},{"type":23,"tag":272,"props":866,"children":867},{"style":344},[868],{"type":28,"value":406},{"type":23,"tag":272,"props":870,"children":872},{"class":274,"line":871},23,[873,877,881],{"type":23,"tag":272,"props":874,"children":875},{"style":279},[876],{"type":28,"value":625},{"type":23,"tag":272,"props":878,"children":879},{"style":279},[880],{"type":28,"value":420},{"type":23,"tag":272,"props":882,"children":883},{"style":290},[884],{"type":28,"value":634},{"type":23,"tag":272,"props":886,"children":888},{"class":274,"line":887},24,[889],{"type":23,"tag":272,"props":890,"children":891},{"style":290},[892],{"type":28,"value":893},"      email,\n",{"type":23,"tag":272,"props":895,"children":897},{"class":274,"line":896},25,[898],{"type":23,"tag":272,"props":899,"children":900},{"style":290},[901],{"type":28,"value":902},"      company\n",{"type":23,"tag":272,"props":904,"children":906},{"class":274,"line":905},26,[907,911],{"type":23,"tag":272,"props":908,"children":909},{"style":279},[910],{"type":28,"value":687},{"type":23,"tag":272,"props":912,"children":913},{"style":290},[914],{"type":28,"value":439},{"type":23,"tag":272,"props":916,"children":918},{"class":274,"line":917},27,[919,924,929,934,939,943],{"type":23,"tag":272,"props":920,"children":921},{"style":279},[922],{"type":28,"value":923},"    WHERE",{"type":23,"tag":272,"props":925,"children":926},{"style":279},[927],{"type":28,"value":928}," NOT",{"type":23,"tag":272,"props":930,"children":931},{"style":290},[932],{"type":28,"value":933}," isdeleted ",{"type":23,"tag":272,"props":935,"children":936},{"style":279},[937],{"type":28,"value":938},"AND",{"type":23,"tag":272,"props":940,"children":941},{"style":279},[942],{"type":28,"value":928},{"type":23,"tag":272,"props":944,"children":945},{"style":290},[946],{"type":28,"value":947}," isconverted\n",{"type":23,"tag":24,"props":949,"children":950},{},[951],{"type":28,"value":952},"We'll build on this in our next example...",{"type":23,"tag":185,"props":954,"children":956},{"id":955},"first-last-touch-with-window-functions",[957],{"type":28,"value":221},{"type":23,"tag":24,"props":959,"children":960},{},[961,963,968],{"type":28,"value":962},"Window functions let you calculate things ",{"type":23,"tag":170,"props":964,"children":965},{},[966],{"type":28,"value":967},"across rows",{"type":28,"value":969}," — like rankings, running totals, or picking the first/last value in a sequence — without collapsing your result into aggregates. SOQL has nothing equivalent.",{"type":23,"tag":24,"props":971,"children":972},{},[973,975,980,982,987],{"type":28,"value":974},"First-touch and last-touch attribution are two of the most common questions in marketing ops: ",{"type":23,"tag":170,"props":976,"children":977},{},[978],{"type":28,"value":979},"what originally brought this lead in?",{"type":28,"value":981}," and ",{"type":23,"tag":170,"props":983,"children":984},{},[985],{"type":28,"value":986},"what was the most recent interaction or the interaction prior to conversion",{"type":28,"value":988},"?",{"type":23,"tag":24,"props":990,"children":991},{},[992,994,999],{"type":28,"value":993},"Salesforce stores a single ",{"type":23,"tag":67,"props":995,"children":996},{"className":7},[997],{"type":28,"value":998},"LeadSource",{"type":28,"value":1000}," field, but your Campaign Member data tells a more complete story.",{"type":23,"tag":263,"props":1002,"children":1004},{"className":265,"code":1003,"language":17,"meta":7,"style":7},"WITH campaign_member_data AS (\n    SELECT\n        cm.leadorcontactid,\n        cp.name campaign_name,\n        cp.type campaign_type,\n        cm.firstrespondeddate,\n        ROW_NUMBER() OVER (PARTITION BY cm.leadorcontactid ORDER BY cm.firstrespondeddate ASC)  AS response_order_asc,\n        ROW_NUMBER() OVER (PARTITION BY cm.leadorcontactid ORDER BY cm.firstrespondeddate DESC) AS response_order_desc\n      FROM {{your_datachef_connection_id}}.campaignmember  cm\n      JOIN {{your_datachef_connection_id}}.campaign cp ON cm.campaignid = cp.id\n      WHERE cm.firstrespondeddate IS NOT NULL\n)\n\n, lead_contact_union AS (\n  SELECT\n      co.id,\n      co.firstname,\n      co.lastname,\n      co.email,\n      a.name company\n    FROM {{your_datachef_connection_id}}.contact co\n    JOIN {{your_datachef_connection_id}}.account a ON a.id = co.accountid\n    UNION\n    SELECT\n      id,\n      firstname,\n      lastname,\n      email,\n      company\n    FROM {{your_datachef_connection_id}}.lead\n    WHERE NOT isdeleted AND NOT isconverted\n)\n\nSELECT \n  lcu.id,\n  lcu.firstname,\n  lcu.lastname,\n  lcu.email,\n  lcu.company,\n  first_touch.campaign_name first_touch_campaign_name,\n  first_touch.campaign_type first_touch_campaign_type,\n  last_touch.campaign_name last_touch_campaign_name,\n  last_touch.campaign_type last_touch_campaign_type\nFROM lead_contact_union lcu\nJOIN campaign_member_data first_touch ON first_touch.leadorcontactid = lcu.id AND first_touch.response_order_asc=1\nJOIN campaign_member_data last_touch ON last_touch.leadorcontactid = lcu.id AND last_touch.response_order_desc=1\n",[1005],{"type":23,"tag":67,"props":1006,"children":1007},{"__ignoreMap":7},[1008,1029,1036,1057,1078,1099,1119,1201,1274,1287,1335,1360,1368,1377,1393,1400,1419,1438,1457,1476,1495,1506,1549,1556,1563,1570,1577,1584,1592,1600,1612,1640,1648,1656,1668,1689,1709,1729,1749,1770,1793,1815,1837,1858,1871,1947],{"type":23,"tag":272,"props":1009,"children":1010},{"class":274,"line":275},[1011,1015,1020,1024],{"type":23,"tag":272,"props":1012,"children":1013},{"style":279},[1014],{"type":28,"value":97},{"type":23,"tag":272,"props":1016,"children":1017},{"style":290},[1018],{"type":28,"value":1019}," campaign_member_data ",{"type":23,"tag":272,"props":1021,"children":1022},{"style":279},[1023],{"type":28,"value":308},{"type":23,"tag":272,"props":1025,"children":1026},{"style":290},[1027],{"type":28,"value":1028}," (\n",{"type":23,"tag":272,"props":1030,"children":1031},{"class":274,"line":316},[1032],{"type":23,"tag":272,"props":1033,"children":1034},{"style":279},[1035],{"type":28,"value":761},{"type":23,"tag":272,"props":1037,"children":1038},{"class":274,"line":330},[1039,1044,1048,1053],{"type":23,"tag":272,"props":1040,"children":1041},{"style":284},[1042],{"type":28,"value":1043},"        cm",{"type":23,"tag":272,"props":1045,"children":1046},{"style":290},[1047],{"type":28,"value":80},{"type":23,"tag":272,"props":1049,"children":1050},{"style":284},[1051],{"type":28,"value":1052},"leadorcontactid",{"type":23,"tag":272,"props":1054,"children":1055},{"style":290},[1056],{"type":28,"value":499},{"type":23,"tag":272,"props":1058,"children":1059},{"class":274,"line":365},[1060,1065,1069,1073],{"type":23,"tag":272,"props":1061,"children":1062},{"style":284},[1063],{"type":28,"value":1064},"        cp",{"type":23,"tag":272,"props":1066,"children":1067},{"style":290},[1068],{"type":28,"value":80},{"type":23,"tag":272,"props":1070,"children":1071},{"style":284},[1072],{"type":28,"value":673},{"type":23,"tag":272,"props":1074,"children":1075},{"style":290},[1076],{"type":28,"value":1077}," campaign_name,\n",{"type":23,"tag":272,"props":1079,"children":1080},{"class":274,"line":395},[1081,1085,1089,1094],{"type":23,"tag":272,"props":1082,"children":1083},{"style":284},[1084],{"type":28,"value":1064},{"type":23,"tag":272,"props":1086,"children":1087},{"style":290},[1088],{"type":28,"value":80},{"type":23,"tag":272,"props":1090,"children":1091},{"style":284},[1092],{"type":28,"value":1093},"type",{"type":23,"tag":272,"props":1095,"children":1096},{"style":290},[1097],{"type":28,"value":1098}," campaign_type,\n",{"type":23,"tag":272,"props":1100,"children":1101},{"class":274,"line":409},[1102,1106,1110,1115],{"type":23,"tag":272,"props":1103,"children":1104},{"style":284},[1105],{"type":28,"value":1043},{"type":23,"tag":272,"props":1107,"children":1108},{"style":290},[1109],{"type":28,"value":80},{"type":23,"tag":272,"props":1111,"children":1112},{"style":284},[1113],{"type":28,"value":1114},"firstrespondeddate",{"type":23,"tag":272,"props":1116,"children":1117},{"style":290},[1118],{"type":28,"value":499},{"type":23,"tag":272,"props":1120,"children":1121},{"class":274,"line":428},[1122,1127,1132,1137,1142,1147,1152,1157,1161,1165,1170,1174,1178,1182,1187,1192,1196],{"type":23,"tag":272,"props":1123,"children":1124},{"style":284},[1125],{"type":28,"value":1126},"        ROW_NUMBER",{"type":23,"tag":272,"props":1128,"children":1129},{"style":290},[1130],{"type":28,"value":1131},"() ",{"type":23,"tag":272,"props":1133,"children":1134},{"style":279},[1135],{"type":28,"value":1136},"OVER",{"type":23,"tag":272,"props":1138,"children":1139},{"style":290},[1140],{"type":28,"value":1141}," (",{"type":23,"tag":272,"props":1143,"children":1144},{"style":279},[1145],{"type":28,"value":1146},"PARTITION",{"type":23,"tag":272,"props":1148,"children":1149},{"style":279},[1150],{"type":28,"value":1151}," BY",{"type":23,"tag":272,"props":1153,"children":1154},{"style":284},[1155],{"type":28,"value":1156}," cm",{"type":23,"tag":272,"props":1158,"children":1159},{"style":290},[1160],{"type":28,"value":80},{"type":23,"tag":272,"props":1162,"children":1163},{"style":284},[1164],{"type":28,"value":1052},{"type":23,"tag":272,"props":1166,"children":1167},{"style":279},[1168],{"type":28,"value":1169}," ORDER BY",{"type":23,"tag":272,"props":1171,"children":1172},{"style":284},[1173],{"type":28,"value":1156},{"type":23,"tag":272,"props":1175,"children":1176},{"style":290},[1177],{"type":28,"value":80},{"type":23,"tag":272,"props":1179,"children":1180},{"style":284},[1181],{"type":28,"value":1114},{"type":23,"tag":272,"props":1183,"children":1184},{"style":279},[1185],{"type":28,"value":1186}," ASC",{"type":23,"tag":272,"props":1188,"children":1189},{"style":290},[1190],{"type":28,"value":1191},")  ",{"type":23,"tag":272,"props":1193,"children":1194},{"style":279},[1195],{"type":28,"value":308},{"type":23,"tag":272,"props":1197,"children":1198},{"style":290},[1199],{"type":28,"value":1200}," response_order_asc,\n",{"type":23,"tag":272,"props":1202,"children":1203},{"class":274,"line":442},[1204,1208,1212,1216,1220,1224,1228,1232,1236,1240,1244,1248,1252,1256,1261,1265,1269],{"type":23,"tag":272,"props":1205,"children":1206},{"style":284},[1207],{"type":28,"value":1126},{"type":23,"tag":272,"props":1209,"children":1210},{"style":290},[1211],{"type":28,"value":1131},{"type":23,"tag":272,"props":1213,"children":1214},{"style":279},[1215],{"type":28,"value":1136},{"type":23,"tag":272,"props":1217,"children":1218},{"style":290},[1219],{"type":28,"value":1141},{"type":23,"tag":272,"props":1221,"children":1222},{"style":279},[1223],{"type":28,"value":1146},{"type":23,"tag":272,"props":1225,"children":1226},{"style":279},[1227],{"type":28,"value":1151},{"type":23,"tag":272,"props":1229,"children":1230},{"style":284},[1231],{"type":28,"value":1156},{"type":23,"tag":272,"props":1233,"children":1234},{"style":290},[1235],{"type":28,"value":80},{"type":23,"tag":272,"props":1237,"children":1238},{"style":284},[1239],{"type":28,"value":1052},{"type":23,"tag":272,"props":1241,"children":1242},{"style":279},[1243],{"type":28,"value":1169},{"type":23,"tag":272,"props":1245,"children":1246},{"style":284},[1247],{"type":28,"value":1156},{"type":23,"tag":272,"props":1249,"children":1250},{"style":290},[1251],{"type":28,"value":80},{"type":23,"tag":272,"props":1253,"children":1254},{"style":284},[1255],{"type":28,"value":1114},{"type":23,"tag":272,"props":1257,"children":1258},{"style":279},[1259],{"type":28,"value":1260}," DESC",{"type":23,"tag":272,"props":1262,"children":1263},{"style":290},[1264],{"type":28,"value":352},{"type":23,"tag":272,"props":1266,"children":1267},{"style":279},[1268],{"type":28,"value":308},{"type":23,"tag":272,"props":1270,"children":1271},{"style":290},[1272],{"type":28,"value":1273}," response_order_desc\n",{"type":23,"tag":272,"props":1275,"children":1276},{"class":274,"line":619},[1277,1282],{"type":23,"tag":272,"props":1278,"children":1279},{"style":279},[1280],{"type":28,"value":1281},"      FROM",{"type":23,"tag":272,"props":1283,"children":1284},{"style":290},[1285],{"type":28,"value":1286}," {{your_datachef_connection_id}}.campaignmember  cm\n",{"type":23,"tag":272,"props":1288,"children":1289},{"class":274,"line":637},[1290,1295,1300,1304,1308,1312,1317,1321,1326,1330],{"type":23,"tag":272,"props":1291,"children":1292},{"style":279},[1293],{"type":28,"value":1294},"      JOIN",{"type":23,"tag":272,"props":1296,"children":1297},{"style":290},[1298],{"type":28,"value":1299}," {{your_datachef_connection_id}}.campaign cp ",{"type":23,"tag":272,"props":1301,"children":1302},{"style":279},[1303],{"type":28,"value":711},{"type":23,"tag":272,"props":1305,"children":1306},{"style":284},[1307],{"type":28,"value":1156},{"type":23,"tag":272,"props":1309,"children":1310},{"style":290},[1311],{"type":28,"value":80},{"type":23,"tag":272,"props":1313,"children":1314},{"style":284},[1315],{"type":28,"value":1316},"campaignid",{"type":23,"tag":272,"props":1318,"children":1319},{"style":279},[1320],{"type":28,"value":729},{"type":23,"tag":272,"props":1322,"children":1323},{"style":284},[1324],{"type":28,"value":1325}," cp",{"type":23,"tag":272,"props":1327,"children":1328},{"style":290},[1329],{"type":28,"value":80},{"type":23,"tag":272,"props":1331,"children":1332},{"style":284},[1333],{"type":28,"value":1334},"id\n",{"type":23,"tag":272,"props":1336,"children":1337},{"class":274,"line":658},[1338,1343,1347,1351,1355],{"type":23,"tag":272,"props":1339,"children":1340},{"style":279},[1341],{"type":28,"value":1342},"      WHERE",{"type":23,"tag":272,"props":1344,"children":1345},{"style":284},[1346],{"type":28,"value":1156},{"type":23,"tag":272,"props":1348,"children":1349},{"style":290},[1350],{"type":28,"value":80},{"type":23,"tag":272,"props":1352,"children":1353},{"style":284},[1354],{"type":28,"value":1114},{"type":23,"tag":272,"props":1356,"children":1357},{"style":279},[1358],{"type":28,"value":1359}," IS NOT NULL\n",{"type":23,"tag":272,"props":1361,"children":1362},{"class":274,"line":681},[1363],{"type":23,"tag":272,"props":1364,"children":1365},{"style":290},[1366],{"type":28,"value":1367},")\n",{"type":23,"tag":272,"props":1369,"children":1370},{"class":274,"line":695},[1371],{"type":23,"tag":272,"props":1372,"children":1374},{"emptyLinePlaceholder":1373},true,[1375],{"type":28,"value":1376},"\n",{"type":23,"tag":272,"props":1378,"children":1379},{"class":274,"line":746},[1380,1385,1389],{"type":23,"tag":272,"props":1381,"children":1382},{"style":290},[1383],{"type":28,"value":1384},", lead_contact_union ",{"type":23,"tag":272,"props":1386,"children":1387},{"style":279},[1388],{"type":28,"value":308},{"type":23,"tag":272,"props":1390,"children":1391},{"style":290},[1392],{"type":28,"value":1028},{"type":23,"tag":272,"props":1394,"children":1395},{"class":274,"line":755},[1396],{"type":23,"tag":272,"props":1397,"children":1398},{"style":279},[1399],{"type":28,"value":477},{"type":23,"tag":272,"props":1401,"children":1402},{"class":274,"line":764},[1403,1407,1411,1415],{"type":23,"tag":272,"props":1404,"children":1405},{"style":284},[1406],{"type":28,"value":485},{"type":23,"tag":272,"props":1408,"children":1409},{"style":290},[1410],{"type":28,"value":80},{"type":23,"tag":272,"props":1412,"children":1413},{"style":284},[1414],{"type":28,"value":494},{"type":23,"tag":272,"props":1416,"children":1417},{"style":290},[1418],{"type":28,"value":499},{"type":23,"tag":272,"props":1420,"children":1421},{"class":274,"line":773},[1422,1426,1430,1434],{"type":23,"tag":272,"props":1423,"children":1424},{"style":284},[1425],{"type":28,"value":485},{"type":23,"tag":272,"props":1427,"children":1428},{"style":290},[1429],{"type":28,"value":80},{"type":23,"tag":272,"props":1431,"children":1432},{"style":284},[1433],{"type":28,"value":515},{"type":23,"tag":272,"props":1435,"children":1436},{"style":290},[1437],{"type":28,"value":499},{"type":23,"tag":272,"props":1439,"children":1440},{"class":274,"line":782},[1441,1445,1449,1453],{"type":23,"tag":272,"props":1442,"children":1443},{"style":284},[1444],{"type":28,"value":485},{"type":23,"tag":272,"props":1446,"children":1447},{"style":290},[1448],{"type":28,"value":80},{"type":23,"tag":272,"props":1450,"children":1451},{"style":284},[1452],{"type":28,"value":535},{"type":23,"tag":272,"props":1454,"children":1455},{"style":290},[1456],{"type":28,"value":499},{"type":23,"tag":272,"props":1458,"children":1459},{"class":274,"line":791},[1460,1464,1468,1472],{"type":23,"tag":272,"props":1461,"children":1462},{"style":284},[1463],{"type":28,"value":485},{"type":23,"tag":272,"props":1465,"children":1466},{"style":290},[1467],{"type":28,"value":80},{"type":23,"tag":272,"props":1469,"children":1470},{"style":284},[1471],{"type":28,"value":651},{"type":23,"tag":272,"props":1473,"children":1474},{"style":290},[1475],{"type":28,"value":499},{"type":23,"tag":272,"props":1477,"children":1478},{"class":274,"line":803},[1479,1483,1487,1491],{"type":23,"tag":272,"props":1480,"children":1481},{"style":284},[1482],{"type":28,"value":664},{"type":23,"tag":272,"props":1484,"children":1485},{"style":290},[1486],{"type":28,"value":80},{"type":23,"tag":272,"props":1488,"children":1489},{"style":284},[1490],{"type":28,"value":673},{"type":23,"tag":272,"props":1492,"children":1493},{"style":290},[1494],{"type":28,"value":678},{"type":23,"tag":272,"props":1496,"children":1497},{"class":274,"line":831},[1498,1502],{"type":23,"tag":272,"props":1499,"children":1500},{"style":279},[1501],{"type":28,"value":687},{"type":23,"tag":272,"props":1503,"children":1504},{"style":290},[1505],{"type":28,"value":692},{"type":23,"tag":272,"props":1507,"children":1508},{"class":274,"line":859},[1509,1513,1517,1521,1525,1529,1533,1537,1541,1545],{"type":23,"tag":272,"props":1510,"children":1511},{"style":279},[1512],{"type":28,"value":701},{"type":23,"tag":272,"props":1514,"children":1515},{"style":290},[1516],{"type":28,"value":706},{"type":23,"tag":272,"props":1518,"children":1519},{"style":279},[1520],{"type":28,"value":711},{"type":23,"tag":272,"props":1522,"children":1523},{"style":284},[1524],{"type":28,"value":716},{"type":23,"tag":272,"props":1526,"children":1527},{"style":290},[1528],{"type":28,"value":80},{"type":23,"tag":272,"props":1530,"children":1531},{"style":284},[1532],{"type":28,"value":494},{"type":23,"tag":272,"props":1534,"children":1535},{"style":279},[1536],{"type":28,"value":729},{"type":23,"tag":272,"props":1538,"children":1539},{"style":284},[1540],{"type":28,"value":734},{"type":23,"tag":272,"props":1542,"children":1543},{"style":290},[1544],{"type":28,"value":80},{"type":23,"tag":272,"props":1546,"children":1547},{"style":284},[1548],{"type":28,"value":743},{"type":23,"tag":272,"props":1550,"children":1551},{"class":274,"line":871},[1552],{"type":23,"tag":272,"props":1553,"children":1554},{"style":279},[1555],{"type":28,"value":752},{"type":23,"tag":272,"props":1557,"children":1558},{"class":274,"line":887},[1559],{"type":23,"tag":272,"props":1560,"children":1561},{"style":279},[1562],{"type":28,"value":761},{"type":23,"tag":272,"props":1564,"children":1565},{"class":274,"line":896},[1566],{"type":23,"tag":272,"props":1567,"children":1568},{"style":290},[1569],{"type":28,"value":770},{"type":23,"tag":272,"props":1571,"children":1572},{"class":274,"line":905},[1573],{"type":23,"tag":272,"props":1574,"children":1575},{"style":290},[1576],{"type":28,"value":779},{"type":23,"tag":272,"props":1578,"children":1579},{"class":274,"line":917},[1580],{"type":23,"tag":272,"props":1581,"children":1582},{"style":290},[1583],{"type":28,"value":788},{"type":23,"tag":272,"props":1585,"children":1587},{"class":274,"line":1586},28,[1588],{"type":23,"tag":272,"props":1589,"children":1590},{"style":290},[1591],{"type":28,"value":893},{"type":23,"tag":272,"props":1593,"children":1595},{"class":274,"line":1594},29,[1596],{"type":23,"tag":272,"props":1597,"children":1598},{"style":290},[1599],{"type":28,"value":902},{"type":23,"tag":272,"props":1601,"children":1603},{"class":274,"line":1602},30,[1604,1608],{"type":23,"tag":272,"props":1605,"children":1606},{"style":279},[1607],{"type":28,"value":687},{"type":23,"tag":272,"props":1609,"children":1610},{"style":290},[1611],{"type":28,"value":439},{"type":23,"tag":272,"props":1613,"children":1615},{"class":274,"line":1614},31,[1616,1620,1624,1628,1632,1636],{"type":23,"tag":272,"props":1617,"children":1618},{"style":279},[1619],{"type":28,"value":923},{"type":23,"tag":272,"props":1621,"children":1622},{"style":279},[1623],{"type":28,"value":928},{"type":23,"tag":272,"props":1625,"children":1626},{"style":290},[1627],{"type":28,"value":933},{"type":23,"tag":272,"props":1629,"children":1630},{"style":279},[1631],{"type":28,"value":938},{"type":23,"tag":272,"props":1633,"children":1634},{"style":279},[1635],{"type":28,"value":928},{"type":23,"tag":272,"props":1637,"children":1638},{"style":290},[1639],{"type":28,"value":947},{"type":23,"tag":272,"props":1641,"children":1643},{"class":274,"line":1642},32,[1644],{"type":23,"tag":272,"props":1645,"children":1646},{"style":290},[1647],{"type":28,"value":1367},{"type":23,"tag":272,"props":1649,"children":1651},{"class":274,"line":1650},33,[1652],{"type":23,"tag":272,"props":1653,"children":1654},{"emptyLinePlaceholder":1373},[1655],{"type":28,"value":1376},{"type":23,"tag":272,"props":1657,"children":1659},{"class":274,"line":1658},34,[1660,1664],{"type":23,"tag":272,"props":1661,"children":1662},{"style":279},[1663],{"type":28,"value":151},{"type":23,"tag":272,"props":1665,"children":1666},{"style":290},[1667],{"type":28,"value":327},{"type":23,"tag":272,"props":1669,"children":1671},{"class":274,"line":1670},35,[1672,1677,1681,1685],{"type":23,"tag":272,"props":1673,"children":1674},{"style":284},[1675],{"type":28,"value":1676},"  lcu",{"type":23,"tag":272,"props":1678,"children":1679},{"style":290},[1680],{"type":28,"value":80},{"type":23,"tag":272,"props":1682,"children":1683},{"style":284},[1684],{"type":28,"value":494},{"type":23,"tag":272,"props":1686,"children":1687},{"style":290},[1688],{"type":28,"value":499},{"type":23,"tag":272,"props":1690,"children":1692},{"class":274,"line":1691},36,[1693,1697,1701,1705],{"type":23,"tag":272,"props":1694,"children":1695},{"style":284},[1696],{"type":28,"value":1676},{"type":23,"tag":272,"props":1698,"children":1699},{"style":290},[1700],{"type":28,"value":80},{"type":23,"tag":272,"props":1702,"children":1703},{"style":284},[1704],{"type":28,"value":515},{"type":23,"tag":272,"props":1706,"children":1707},{"style":290},[1708],{"type":28,"value":499},{"type":23,"tag":272,"props":1710,"children":1712},{"class":274,"line":1711},37,[1713,1717,1721,1725],{"type":23,"tag":272,"props":1714,"children":1715},{"style":284},[1716],{"type":28,"value":1676},{"type":23,"tag":272,"props":1718,"children":1719},{"style":290},[1720],{"type":28,"value":80},{"type":23,"tag":272,"props":1722,"children":1723},{"style":284},[1724],{"type":28,"value":535},{"type":23,"tag":272,"props":1726,"children":1727},{"style":290},[1728],{"type":28,"value":499},{"type":23,"tag":272,"props":1730,"children":1732},{"class":274,"line":1731},38,[1733,1737,1741,1745],{"type":23,"tag":272,"props":1734,"children":1735},{"style":284},[1736],{"type":28,"value":1676},{"type":23,"tag":272,"props":1738,"children":1739},{"style":290},[1740],{"type":28,"value":80},{"type":23,"tag":272,"props":1742,"children":1743},{"style":284},[1744],{"type":28,"value":651},{"type":23,"tag":272,"props":1746,"children":1747},{"style":290},[1748],{"type":28,"value":499},{"type":23,"tag":272,"props":1750,"children":1752},{"class":274,"line":1751},39,[1753,1757,1761,1766],{"type":23,"tag":272,"props":1754,"children":1755},{"style":284},[1756],{"type":28,"value":1676},{"type":23,"tag":272,"props":1758,"children":1759},{"style":290},[1760],{"type":28,"value":80},{"type":23,"tag":272,"props":1762,"children":1763},{"style":284},[1764],{"type":28,"value":1765},"company",{"type":23,"tag":272,"props":1767,"children":1768},{"style":290},[1769],{"type":28,"value":499},{"type":23,"tag":272,"props":1771,"children":1773},{"class":274,"line":1772},40,[1774,1779,1783,1788],{"type":23,"tag":272,"props":1775,"children":1776},{"style":284},[1777],{"type":28,"value":1778},"  first_touch",{"type":23,"tag":272,"props":1780,"children":1781},{"style":290},[1782],{"type":28,"value":80},{"type":23,"tag":272,"props":1784,"children":1785},{"style":284},[1786],{"type":28,"value":1787},"campaign_name",{"type":23,"tag":272,"props":1789,"children":1790},{"style":290},[1791],{"type":28,"value":1792}," first_touch_campaign_name,\n",{"type":23,"tag":272,"props":1794,"children":1796},{"class":274,"line":1795},41,[1797,1801,1805,1810],{"type":23,"tag":272,"props":1798,"children":1799},{"style":284},[1800],{"type":28,"value":1778},{"type":23,"tag":272,"props":1802,"children":1803},{"style":290},[1804],{"type":28,"value":80},{"type":23,"tag":272,"props":1806,"children":1807},{"style":284},[1808],{"type":28,"value":1809},"campaign_type",{"type":23,"tag":272,"props":1811,"children":1812},{"style":290},[1813],{"type":28,"value":1814}," first_touch_campaign_type,\n",{"type":23,"tag":272,"props":1816,"children":1818},{"class":274,"line":1817},42,[1819,1824,1828,1832],{"type":23,"tag":272,"props":1820,"children":1821},{"style":284},[1822],{"type":28,"value":1823},"  last_touch",{"type":23,"tag":272,"props":1825,"children":1826},{"style":290},[1827],{"type":28,"value":80},{"type":23,"tag":272,"props":1829,"children":1830},{"style":284},[1831],{"type":28,"value":1787},{"type":23,"tag":272,"props":1833,"children":1834},{"style":290},[1835],{"type":28,"value":1836}," last_touch_campaign_name,\n",{"type":23,"tag":272,"props":1838,"children":1840},{"class":274,"line":1839},43,[1841,1845,1849,1853],{"type":23,"tag":272,"props":1842,"children":1843},{"style":284},[1844],{"type":28,"value":1823},{"type":23,"tag":272,"props":1846,"children":1847},{"style":290},[1848],{"type":28,"value":80},{"type":23,"tag":272,"props":1850,"children":1851},{"style":284},[1852],{"type":28,"value":1809},{"type":23,"tag":272,"props":1854,"children":1855},{"style":290},[1856],{"type":28,"value":1857}," last_touch_campaign_type\n",{"type":23,"tag":272,"props":1859,"children":1861},{"class":274,"line":1860},44,[1862,1866],{"type":23,"tag":272,"props":1863,"children":1864},{"style":279},[1865],{"type":28,"value":434},{"type":23,"tag":272,"props":1867,"children":1868},{"style":290},[1869],{"type":28,"value":1870}," lead_contact_union lcu\n",{"type":23,"tag":272,"props":1872,"children":1874},{"class":274,"line":1873},45,[1875,1880,1885,1889,1894,1898,1902,1906,1911,1915,1919,1924,1928,1932,1937,1942],{"type":23,"tag":272,"props":1876,"children":1877},{"style":279},[1878],{"type":28,"value":1879},"JOIN",{"type":23,"tag":272,"props":1881,"children":1882},{"style":290},[1883],{"type":28,"value":1884}," campaign_member_data first_touch ",{"type":23,"tag":272,"props":1886,"children":1887},{"style":279},[1888],{"type":28,"value":711},{"type":23,"tag":272,"props":1890,"children":1891},{"style":284},[1892],{"type":28,"value":1893}," first_touch",{"type":23,"tag":272,"props":1895,"children":1896},{"style":290},[1897],{"type":28,"value":80},{"type":23,"tag":272,"props":1899,"children":1900},{"style":284},[1901],{"type":28,"value":1052},{"type":23,"tag":272,"props":1903,"children":1904},{"style":279},[1905],{"type":28,"value":729},{"type":23,"tag":272,"props":1907,"children":1908},{"style":284},[1909],{"type":28,"value":1910}," lcu",{"type":23,"tag":272,"props":1912,"children":1913},{"style":290},[1914],{"type":28,"value":80},{"type":23,"tag":272,"props":1916,"children":1917},{"style":284},[1918],{"type":28,"value":494},{"type":23,"tag":272,"props":1920,"children":1921},{"style":279},[1922],{"type":28,"value":1923}," AND",{"type":23,"tag":272,"props":1925,"children":1926},{"style":284},[1927],{"type":28,"value":1893},{"type":23,"tag":272,"props":1929,"children":1930},{"style":290},[1931],{"type":28,"value":80},{"type":23,"tag":272,"props":1933,"children":1934},{"style":284},[1935],{"type":28,"value":1936},"response_order_asc",{"type":23,"tag":272,"props":1938,"children":1939},{"style":279},[1940],{"type":28,"value":1941},"=",{"type":23,"tag":272,"props":1943,"children":1944},{"style":284},[1945],{"type":28,"value":1946},"1\n",{"type":23,"tag":272,"props":1948,"children":1950},{"class":274,"line":1949},46,[1951,1955,1960,1964,1969,1973,1977,1981,1985,1989,1993,1997,2001,2005,2010,2014],{"type":23,"tag":272,"props":1952,"children":1953},{"style":279},[1954],{"type":28,"value":1879},{"type":23,"tag":272,"props":1956,"children":1957},{"style":290},[1958],{"type":28,"value":1959}," campaign_member_data last_touch ",{"type":23,"tag":272,"props":1961,"children":1962},{"style":279},[1963],{"type":28,"value":711},{"type":23,"tag":272,"props":1965,"children":1966},{"style":284},[1967],{"type":28,"value":1968}," last_touch",{"type":23,"tag":272,"props":1970,"children":1971},{"style":290},[1972],{"type":28,"value":80},{"type":23,"tag":272,"props":1974,"children":1975},{"style":284},[1976],{"type":28,"value":1052},{"type":23,"tag":272,"props":1978,"children":1979},{"style":279},[1980],{"type":28,"value":729},{"type":23,"tag":272,"props":1982,"children":1983},{"style":284},[1984],{"type":28,"value":1910},{"type":23,"tag":272,"props":1986,"children":1987},{"style":290},[1988],{"type":28,"value":80},{"type":23,"tag":272,"props":1990,"children":1991},{"style":284},[1992],{"type":28,"value":494},{"type":23,"tag":272,"props":1994,"children":1995},{"style":279},[1996],{"type":28,"value":1923},{"type":23,"tag":272,"props":1998,"children":1999},{"style":284},[2000],{"type":28,"value":1968},{"type":23,"tag":272,"props":2002,"children":2003},{"style":290},[2004],{"type":28,"value":80},{"type":23,"tag":272,"props":2006,"children":2007},{"style":284},[2008],{"type":28,"value":2009},"response_order_desc",{"type":23,"tag":272,"props":2011,"children":2012},{"style":279},[2013],{"type":28,"value":1941},{"type":23,"tag":272,"props":2015,"children":2016},{"style":284},[2017],{"type":28,"value":1946},{"type":23,"tag":24,"props":2019,"children":2020},{},[2021],{"type":28,"value":2022},"This gives you a row per Lead or Contact, showing exactly which campaign first got their attention and which one they responded to most recently.",{"type":23,"tag":185,"props":2024,"children":2026},{"id":2025},"cross-platform-queries-eg-salesforce-marketo",[2027],{"type":28,"value":230},{"type":23,"tag":24,"props":2029,"children":2030},{},[2031,2033,2038],{"type":28,"value":2032},"SOQL can only query Salesforce. But of course it cannot query things ",{"type":23,"tag":170,"props":2034,"children":2035},{},[2036],{"type":28,"value":2037},"outside",{"type":28,"value":2039}," of Salesforce.",{"type":23,"tag":24,"props":2041,"children":2042},{},[2043],{"type":28,"value":2044},"So, if you've connected both Salesforce and a marketing platform like Marketo, you can perform advanced joins and performance analysis on combined data sets.",{"type":23,"tag":24,"props":2046,"children":2047},{},[2048],{"type":28,"value":2049},"Here is an example where we join Contacts to Marketo Leads (People) and get the most recent Marketo activity date for each person.",{"type":23,"tag":263,"props":2051,"children":2053},{"className":265,"code":2052,"language":17,"meta":7,"style":7},"SELECT \n    ml.id AS marketo_lead_id,\n    sf_co.id AS salesforce_contact_id,\n    act.activitydate AS last_activity_date\nFROM {{your_salesforce_connection_id}}.lead ml\nJOIN {{your_marketo_connection_id}}.contact sf_co USING (email)\nJOIN (\n    SELECT *,\n        ROW_NUMBER() OVER (PARTITION BY leadid ORDER BY activitydate DESC) AS rn\n    FROM {{your_marketo_connection_id}}.activity\n) act ON act.leadid = ml.id AND act.rn = 1\n\n",[2054],{"type":23,"tag":67,"props":2055,"children":2056},{"__ignoreMap":7},[2057,2068,2093,2118,2144,2156,2178,2189,2206,2266,2278],{"type":23,"tag":272,"props":2058,"children":2059},{"class":274,"line":275},[2060,2064],{"type":23,"tag":272,"props":2061,"children":2062},{"style":279},[2063],{"type":28,"value":151},{"type":23,"tag":272,"props":2065,"children":2066},{"style":290},[2067],{"type":28,"value":327},{"type":23,"tag":272,"props":2069,"children":2070},{"class":274,"line":316},[2071,2076,2080,2084,2088],{"type":23,"tag":272,"props":2072,"children":2073},{"style":284},[2074],{"type":28,"value":2075},"    ml",{"type":23,"tag":272,"props":2077,"children":2078},{"style":290},[2079],{"type":28,"value":80},{"type":23,"tag":272,"props":2081,"children":2082},{"style":284},[2083],{"type":28,"value":494},{"type":23,"tag":272,"props":2085,"children":2086},{"style":279},[2087],{"type":28,"value":420},{"type":23,"tag":272,"props":2089,"children":2090},{"style":290},[2091],{"type":28,"value":2092}," marketo_lead_id,\n",{"type":23,"tag":272,"props":2094,"children":2095},{"class":274,"line":330},[2096,2101,2105,2109,2113],{"type":23,"tag":272,"props":2097,"children":2098},{"style":284},[2099],{"type":28,"value":2100},"    sf_co",{"type":23,"tag":272,"props":2102,"children":2103},{"style":290},[2104],{"type":28,"value":80},{"type":23,"tag":272,"props":2106,"children":2107},{"style":284},[2108],{"type":28,"value":494},{"type":23,"tag":272,"props":2110,"children":2111},{"style":279},[2112],{"type":28,"value":420},{"type":23,"tag":272,"props":2114,"children":2115},{"style":290},[2116],{"type":28,"value":2117}," salesforce_contact_id,\n",{"type":23,"tag":272,"props":2119,"children":2120},{"class":274,"line":365},[2121,2126,2130,2135,2139],{"type":23,"tag":272,"props":2122,"children":2123},{"style":284},[2124],{"type":28,"value":2125},"    act",{"type":23,"tag":272,"props":2127,"children":2128},{"style":290},[2129],{"type":28,"value":80},{"type":23,"tag":272,"props":2131,"children":2132},{"style":284},[2133],{"type":28,"value":2134},"activitydate",{"type":23,"tag":272,"props":2136,"children":2137},{"style":279},[2138],{"type":28,"value":420},{"type":23,"tag":272,"props":2140,"children":2141},{"style":290},[2142],{"type":28,"value":2143}," last_activity_date\n",{"type":23,"tag":272,"props":2145,"children":2146},{"class":274,"line":395},[2147,2151],{"type":23,"tag":272,"props":2148,"children":2149},{"style":279},[2150],{"type":28,"value":434},{"type":23,"tag":272,"props":2152,"children":2153},{"style":290},[2154],{"type":28,"value":2155}," {{your_salesforce_connection_id}}.lead ml\n",{"type":23,"tag":272,"props":2157,"children":2158},{"class":274,"line":409},[2159,2163,2168,2173],{"type":23,"tag":272,"props":2160,"children":2161},{"style":279},[2162],{"type":28,"value":1879},{"type":23,"tag":272,"props":2164,"children":2165},{"style":290},[2166],{"type":28,"value":2167}," {{your_marketo_connection_id}}.contact sf_co ",{"type":23,"tag":272,"props":2169,"children":2170},{"style":279},[2171],{"type":28,"value":2172},"USING",{"type":23,"tag":272,"props":2174,"children":2175},{"style":290},[2176],{"type":28,"value":2177}," (email)\n",{"type":23,"tag":272,"props":2179,"children":2180},{"class":274,"line":428},[2181,2185],{"type":23,"tag":272,"props":2182,"children":2183},{"style":279},[2184],{"type":28,"value":1879},{"type":23,"tag":272,"props":2186,"children":2187},{"style":290},[2188],{"type":28,"value":1028},{"type":23,"tag":272,"props":2190,"children":2191},{"class":274,"line":442},[2192,2197,2202],{"type":23,"tag":272,"props":2193,"children":2194},{"style":279},[2195],{"type":28,"value":2196},"    SELECT",{"type":23,"tag":272,"props":2198,"children":2199},{"style":279},[2200],{"type":28,"value":2201}," *",{"type":23,"tag":272,"props":2203,"children":2204},{"style":290},[2205],{"type":28,"value":499},{"type":23,"tag":272,"props":2207,"children":2208},{"class":274,"line":619},[2209,2213,2217,2221,2225,2229,2233,2238,2243,2248,2253,2257,2261],{"type":23,"tag":272,"props":2210,"children":2211},{"style":284},[2212],{"type":28,"value":1126},{"type":23,"tag":272,"props":2214,"children":2215},{"style":290},[2216],{"type":28,"value":1131},{"type":23,"tag":272,"props":2218,"children":2219},{"style":279},[2220],{"type":28,"value":1136},{"type":23,"tag":272,"props":2222,"children":2223},{"style":290},[2224],{"type":28,"value":1141},{"type":23,"tag":272,"props":2226,"children":2227},{"style":279},[2228],{"type":28,"value":1146},{"type":23,"tag":272,"props":2230,"children":2231},{"style":279},[2232],{"type":28,"value":1151},{"type":23,"tag":272,"props":2234,"children":2235},{"style":290},[2236],{"type":28,"value":2237}," leadid ",{"type":23,"tag":272,"props":2239,"children":2240},{"style":279},[2241],{"type":28,"value":2242},"ORDER BY",{"type":23,"tag":272,"props":2244,"children":2245},{"style":290},[2246],{"type":28,"value":2247}," activitydate ",{"type":23,"tag":272,"props":2249,"children":2250},{"style":279},[2251],{"type":28,"value":2252},"DESC",{"type":23,"tag":272,"props":2254,"children":2255},{"style":290},[2256],{"type":28,"value":352},{"type":23,"tag":272,"props":2258,"children":2259},{"style":279},[2260],{"type":28,"value":308},{"type":23,"tag":272,"props":2262,"children":2263},{"style":290},[2264],{"type":28,"value":2265}," rn\n",{"type":23,"tag":272,"props":2267,"children":2268},{"class":274,"line":637},[2269,2273],{"type":23,"tag":272,"props":2270,"children":2271},{"style":279},[2272],{"type":28,"value":687},{"type":23,"tag":272,"props":2274,"children":2275},{"style":290},[2276],{"type":28,"value":2277}," {{your_marketo_connection_id}}.activity\n",{"type":23,"tag":272,"props":2279,"children":2280},{"class":274,"line":658},[2281,2286,2290,2295,2299,2304,2308,2313,2317,2321,2325,2329,2333,2338,2342],{"type":23,"tag":272,"props":2282,"children":2283},{"style":290},[2284],{"type":28,"value":2285},") act ",{"type":23,"tag":272,"props":2287,"children":2288},{"style":279},[2289],{"type":28,"value":711},{"type":23,"tag":272,"props":2291,"children":2292},{"style":284},[2293],{"type":28,"value":2294}," act",{"type":23,"tag":272,"props":2296,"children":2297},{"style":290},[2298],{"type":28,"value":80},{"type":23,"tag":272,"props":2300,"children":2301},{"style":284},[2302],{"type":28,"value":2303},"leadid",{"type":23,"tag":272,"props":2305,"children":2306},{"style":279},[2307],{"type":28,"value":729},{"type":23,"tag":272,"props":2309,"children":2310},{"style":284},[2311],{"type":28,"value":2312}," ml",{"type":23,"tag":272,"props":2314,"children":2315},{"style":290},[2316],{"type":28,"value":80},{"type":23,"tag":272,"props":2318,"children":2319},{"style":284},[2320],{"type":28,"value":494},{"type":23,"tag":272,"props":2322,"children":2323},{"style":279},[2324],{"type":28,"value":1923},{"type":23,"tag":272,"props":2326,"children":2327},{"style":284},[2328],{"type":28,"value":2294},{"type":23,"tag":272,"props":2330,"children":2331},{"style":290},[2332],{"type":28,"value":80},{"type":23,"tag":272,"props":2334,"children":2335},{"style":284},[2336],{"type":28,"value":2337},"rn",{"type":23,"tag":272,"props":2339,"children":2340},{"style":279},[2341],{"type":28,"value":729},{"type":23,"tag":272,"props":2343,"children":2344},{"style":284},[2345],{"type":28,"value":2346}," 1\n",{"type":23,"tag":232,"props":2348,"children":2349},{},[],{"type":23,"tag":24,"props":2351,"children":2352},{},[2353],{"type":23,"tag":170,"props":2354,"children":2355},{},[2356],{"type":28,"value":2357},"Want to explore your Salesforce data with SQL?",{"type":23,"tag":24,"props":2359,"children":2360},{},[2361],{"type":23,"tag":170,"props":2362,"children":2363},{},[2364,2370,2372,2380],{"type":23,"tag":198,"props":2365,"children":2367},{"href":2366},"/demo",[2368],{"type":28,"value":2369},"Watch a demo",{"type":28,"value":2371}," to see more interesting use cases or ",{"type":23,"tag":198,"props":2373,"children":2377},{"href":2374,"rel":2375},"https://app.datachef.com/login?utm_source=blog&utm_content=sql-for-marketers",[2376],"nofollow",[2378],{"type":28,"value":2379},"try Datachef free for 14 days",{"type":28,"value":80},{"type":23,"tag":2382,"props":2383,"children":2384},"style",{},[2385],{"type":28,"value":2386},"html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":7,"searchDepth":316,"depth":316,"links":2388},[2389,2390,2391,2392,2393],{"id":187,"depth":316,"text":190},{"id":237,"depth":316,"text":203},{"id":455,"depth":316,"text":212},{"id":955,"depth":316,"text":221},{"id":2025,"depth":316,"text":230},"markdown","content:blog:overcoming-soql-limits.md","content","blog/overcoming-soql-limits.md","md",1779898546925]