{"id":22770,"date":"2023-06-08T11:56:41","date_gmt":"2023-06-08T09:56:41","guid":{"rendered":"https:\/\/www.marketinet.com\/blog\/examples-dataviews-sql-query-salesforce-marketing-cloud\/"},"modified":"2025-04-04T11:57:10","modified_gmt":"2025-04-04T09:57:10","slug":"examples-dataviews-sql-query-salesforce-marketing-cloud","status":"publish","type":"post","link":"https:\/\/www.marketinet.com\/en\/blog\/examples-dataviews-sql-query-salesforce-marketing-cloud\/","title":{"rendered":"How to Use DataViews with SQL in Salesforce Marketing Cloud"},"content":{"rendered":"<p>As we have commented in previous articles, if we want to <a href=\"\/en\/thedigitalmarketinglab\/main-advantages-of-segmentation-in-salesforce-marketing-cloud\" rel=\"noopener\">improve our segmentations<\/a> and especially our results in our Marketing Cloud strategy, it is essential to develop increasingly precise queries, and this is where DataViews come into play.<\/p>\n<p><!--more--><\/p>\n<p>If we want to identify a potential customer of a product, a signal may be that in a generic email, the user clicks on the link of that product. Also, a customer always clicks on a specific product category. For this, it is important to use the LinkName intelligently. Many times only a descriptive name is used, but if you put a category, a separator and then the descriptive name, it will activate other interesting options to identify users who are interested not only in a specific product but in a category as such.<\/p>\n<p>\u00a0<\/p>\n<p>{{cta(&#8217;52fa9c99-860e-4fbd-b8e0-8084060f20e8&#8242;,&#8217;justifycenter&#8217;)}}<\/p>\n<h2>A first query to know the status of the subscribers<\/h2>\n<p>\u00a0<\/p>\n<p>A very simple first query can be the status of your subscribers in a DE, through this query you can see the true impact or final delivery that you will have based on that status:<\/p>\n<p>\u00a0<\/p>\n<p><em>SELECT firstname, de.lastname, de.cathegory, de.email, s.[Status]<\/em><br \/><em>FROM Test_Data_Extension as de LEFT JOIN _Subscribers s<\/em><br \/><em>ON email=s.SubscriberKey<\/em><\/p>\n<p><iframe data-src=\"https:\/\/pastebin.com\/embed_iframe\/ALR4ugV0?theme=dark\" width=\"560\" height=\"125\" data-service=\"pastebin\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/p>\n<p>\u00a0<\/p>\n<p>Through this query, those with NULL status will probably be new users or simply that it is the first time that you send them something through Marketing Cloud.<\/p>\n<p>\u00a0<\/p>\n<h2>Reinsistence Email to Non-Openers<\/h2>\n<p>\u00a0<\/p>\n<p>One option with DataViews queries is to retry a second submission to users who didn&#8217;t open it the first time. If they have not opened it, the best options that you can choose to improve the results focus on 2 variables; the \u201cFrom\u201d and the \u201cSubject\u201d, modify one or both and try to seduce those users that you didn&#8217;t succeed in the first try.<\/p>\n<p>To carry out this query you need the JobID of your shipment, if you activated tracking, it&#8217;s simple, go to Tracking and locate your shipment, what you need is the aforementioned JobID<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/www.marketinet.com\/wp-content\/uploads\/2024\/06\/articulos\/salesforce-marketing-cloud\/tracking-job-id.png\" alt=\"My tracking Salesforce\" width=\"602\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 602px; --smush-placeholder-aspect-ratio: 602\/124;\" \/><\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n<p>With that number you can already make the query\u2026<\/p>\n<p>\u00a0<\/p>\n<div><em>SELECT SubscriberKey<\/em><\/div>\n<div><em>FROM \u00a0 \u00a0TuDataExtension<\/em><\/div>\n<div><em>WHERE <\/em><\/div>\n<div><em>SubscriberKey NOT IN<\/em><\/div>\n<div><em>(SELECT SubscriberKey FROM _open WHERE JobId=\u20191234567\u2019)<\/em><\/div>\n<div>\u00a0<\/div>\n<div>\u00a0<\/div>\n<div>\u00a0<\/div>\n<p><iframe data-src=\"https:\/\/pastebin.com\/embed_iframe\/HgkvdxeB?theme=dark\" width=\"560\" height=\"135\" data-service=\"pastebin\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/p>\n<p>\u00a0<\/p>\n<h2>Openers of a shipment<\/h2>\n<p>If we make a sequence of submissions, but<strong> we want to send that second submission only to users that we know have opened the communication, we can use this query using the JobID as well.<\/strong><\/p>\n<p>SELECT de.SubscriberKey<\/p>\n<p>FROM YourDataExtension of<\/p>\n<p>INNER JOIN _open o<\/p>\n<p>ON o.SubscriberKey=de. SubscriberKey<\/p>\n<p>WHERE<\/p>\n<p>o.JobId=\u20191234567\u2019<\/p>\n<p>AND o.IsUnique=&#8217;True&#8217;<\/p>\n<p>\u00a0<\/p>\n<p><iframe data-src=\"https:\/\/pastebin.com\/embed_iframe\/Gru7VJWv?theme=dark\" width=\"560\" height=\"255\" data-service=\"pastebin\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/p>\n<p>\u00a0<\/p>\n<h2>And if, in addition, we want to know that they did not click<\/h2>\n<p>Many times we manage to capture attention with the subject, but once inside, the user shows no further interest and does not click on any of the links included. The reasons can be multiple:<\/p>\n<p>\u00a0<\/p>\n<ul>\n<li>\n<p>upon entering<strong> they see that it was not what they expected<\/strong> (the subject confused them).<\/p>\n<\/li>\n<li>\n<p><strong>expectations were greater than what they found.<\/strong><\/p>\n<\/li>\n<li>\n<p>a friend <strong>called them at that moment and told them something so interesting that later they forgot<\/strong> to click.<\/p>\n<\/li>\n<li>\n<p>or maybe<strong> they did not understand the offer well.<\/strong><\/p>\n<\/li>\n<li>\n<p>or<strong> other reasons.<\/strong><\/p>\n<\/li>\n<\/ul>\n<p>The key is to analyze the message sent, to see if we can take advantage of the fact that they at least saw it to go with a sequential option or a different option.<\/p>\n<p>\u00a0<\/p>\n<p>SELECT SubscriberKey<br \/>FROM TuDataExtension<br \/>WHERE SubscriberKey IN<\/p>\n<p>(SELECT SubscriberKey FROM _open WHERE JobId=\u20191234567\u2019)<\/p>\n<p>AND SubscriberKey NOT IN<\/p>\n<p>(SELECT SubscriberKey FROM _click WHERE JobId=\u20191234567\u2019)<\/p>\n<p>\u00a0<\/p>\n<p><iframe data-src=\"https:\/\/pastebin.com\/embed_iframe\/JtKn6Pn8?theme=dark\" width=\"560\" height=\"200\" data-service=\"pastebin\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/p>\n<p>\u00a0<\/p>\n<p>It may also be that you are interested in the fact that they have also clicked (they still arrived, but they did not convert), in this case, by changing the last NOT IN to simply IN, you have already done it.<\/p>\n<p>\u00a0<\/p>\n<h2>What if I want to know who clicked on a particular link?<\/h2>\n<p>\u00a0<\/p>\n<p>Imagine that you send a very generic email with a bunch of hardware products, but you want to send a subsequent email only to those who showed interest in NAS products with an irresistible offer.<\/p>\n<p><br \/>With this query, you can get those subscribers:<\/p>\n<p>\u00a0<\/p>\n<p>SELECT linkname,JOBid, s.EmailAddress, s.SubscriberKey<br \/>FROM _Click c<\/p>\n<p>INNER JOIN _subscribers s<\/p>\n<p>ON c.SubscriberID=s.SubscriberID<\/p>\n<p>WHERE IsUnique=&#8217;true&#8217; AND JobId=\u20191234567\u2019<br \/>AND linkname=&#8217;Productos NAS&#8217;<\/p>\n<p>\u00a0<\/p>\n<p><iframe data-src=\"https:\/\/pastebin.com\/embed_iframe\/NiqXbGkS?theme=dark\" width=\"560\" height=\"215\" data-service=\"pastebin\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/p>\n<p>\u00a0<\/p>\n<h2>Recover the &#8220;asleep&#8221;<\/h2>\n<p>We receive more and more emails, and we sign up with great enthusiasm, but then we start to decline,<strong> it is good to detect these sleepy people before they fall into an infinite sleep.<\/strong><\/p>\n<p>\u00a0<\/p>\n<p>A fresh communication, a promo just for them, we have to look for some resources <strong>to revive them and also offer them to modify their preferences or frequencies.<\/strong><\/p>\n<p>\u00a0<\/p>\n<p><span lang=\"en\">To identify these sleepers with 30 days without activity, here is a query:<\/span><\/p>\n<p>SELECT DISTINCT s.SubscriberKey<br \/>FROM _Sent s<br \/>LEFT JOIN _Job j<br \/>ON s.JobID = j.JobID<br \/>LEFT JOIN _Open o<br \/>ON s.JobID = o.JobID AND s.ListID = o.ListID AND s.BatchID = o.BatchID AND s.SubscriberID = o.SubscriberID AND o.IsUnique = 1<br \/>LEFT JOIN _Click c<br \/>ON s.JobID = c.JobID AND s.ListID = c.ListID AND s.BatchID = c.BatchID AND s.SubscriberID = c.SubscriberID AND c.IsUnique = 1<br \/>WHERE<br \/>s.EventDate &gt; dateadd(d,-30,getdate())<br \/>AND (o.SubscriberID is NULL AND c.SubscriberID is NULL)<\/p>\n<p>\u00a0<\/p>\n<p><iframe data-src=\"https:\/\/pastebin.com\/embed_iframe\/5FZEmtLV?theme=dark\" width=\"560\" height=\"315\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe><\/p>\n<p>\u00a0<\/p>\n<h2><strong>Conclusion<\/strong><\/h2>\n<p>\u00a0<\/p>\n<p>This is just a generic sample of things you can do with DataViews, but this can be used much more customized to your needs depending on your business, target, and the types of communications you do. If you use journeys, there are also dataViews, also for the mobile part, etc. In the end, the goal is to make segmentations increasingly intelligent and effective.<\/p>\n<p>\u00a0<\/p>\n<hr \/>\n<p>If you liked this article, you might also be interested in:<\/p>\n<ul>\n<li><a href=\"\/en\/thedigitalmarketinglab\/we-are-salesforce-marketing-cloud-official-partner-agency\" target=\"_blank\" rel=\"noopener\">We are Salesforce Marketing Cloud Official Partner Agency<\/a><\/li>\n<li><a href=\"\/en\/thedigitalmarketinglab\/main-advantages-of-segmentation-in-salesforce-marketing-cloud\" target=\"_blank\" rel=\"noopener\">Main advantages of segmentation in Salesforce Marketing Cloud<\/a>\u00a0<\/li>\n<\/ul>\n<p>{{cta(&#8216;da84ff16-530b-4d9d-bc78-b7102ff27b51&#8242;,&#8217;justifycenter&#8217;)}}<\/p>\n<p>\u00a0<\/p>\n<p>\u00a0<\/p>\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.marketinet.com\/en\/ebooks\/ecosystem-data-marketing-cloud?utm_source=blog&amp;utm_medium=inbound&amp;utm_campaign=cta_recurso_blog_ebook_ecosistema_de_datos_en_salesforce_marketing_cloud_-_en\"><img decoding=\"async\" width=\"800\" height=\"200\" data-src=\"https:\/\/www.marketinet.com\/wp-content\/uploads\/2024\/01\/800x200_banner_ebook-2.jpg\" alt=\"eBook Data Ecosystem in Salesforce Marketing Cloud \" class=\"wp-image-1232 lazyload\" data-srcset=\"https:\/\/www.marketinet.com\/wp-content\/uploads\/2024\/01\/800x200_banner_ebook-2.jpg 800w, https:\/\/www.marketinet.com\/wp-content\/uploads\/2024\/01\/800x200_banner_ebook-2-480x120.jpg 480w\" data-sizes=\"(min-width: 0px) and (max-width: 480px) 480px, (min-width: 481px) 800px, 100vw\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 800px; --smush-placeholder-aspect-ratio: 800\/200;\" \/><\/a><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>As we have commented in previous articles, if we want to improve our segmentations and especially our results in our Marketing Cloud strategy, it is essential to develop increasingly precise queries, and this is where DataViews come into play.<\/p>\n","protected":false},"author":36,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1],"tags":[165],"class_list":["post-22770","post","type-post","status-publish","format-standard","hentry","category-sin-categorizar","tag-sf-marketing-cloud"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/posts\/22770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/comments?post=22770"}],"version-history":[{"count":0,"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/posts\/22770\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/media?parent=22770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/categories?post=22770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.marketinet.com\/en\/wp-json\/wp\/v2\/tags?post=22770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}