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