I maintain a Craft 3.4.17.1 site for a non-profit client and it's grant-reporting season. My client has asked me to put together a quick-turnaround offline report of all the content we published this year across several sections of our site, so that we can do some analysis around our authors, topics, etc. No problem, I said! Totes easy, I said! Lol. Loooool.
Can someone please help me to understand how I write a SQL query for retrieving some field values such as entry title for ONLY THE CURRENT/LIVE VERSION/DRAFT of entries?
For a while it seemed like the key would be to exclude rows where the elements table had any values for revisionId or draftId—but that was a false ray of hope, because we have a relational field, "Contributor," for the content entries I'm focused on, which points to to author—profile type entries that I'll need to join to grab the author names, and in some cases the craft_relations row containing the relevant fieldId only exists in association with a craft_elements row that does have non-null revisionId or draftId.
So now I'm back to just blankly staring at my SQL editor, unable to puzzle out how Craft keeps track of all the revisions/drafts/entries of all the entries/elements/content that make up one lil blog post on our website. Halp? Thank you very much in advance.
(I want to acknowledge that it seems as if, if I were willing to both upgrade to 3.7+ and also write the whole report in Craft queries instead of SQL, this would be more intuitive to accomplish. However, for a one-off/internal-use-only use case, I'm not trying to sign up for that level of prerequisite effort plus a maintenance window/content freeze on our public-facing site, vs what I thought would be a hour or two of SQL noodling on a local copy of our database—and which WOULD be that in other, not-necessarily-at-all-superior CMSes that will go unnamed!)
(Also also: I did attempt to install a trial of Sprout Reports to see if that'd do this job for me, but it just throws gnarly CP errors once installed, so.)