Query SQL with inner join

Query SQL with inner join

Hi,

I have a transaction table with heaps of rows. I want to create a SQL script that gets all transactions with the minimum transaction date. Eventually I want to purge/delete old rows using the delete API.

Logically this is two steps:
1. Get minimum trans date from transaction table.
2. Select all rows in the transaction table where trans date equals the minimum trans date from previous step.

I tried the following 2 SQL statements but receive different errors messages:
SELECT
     COUNT(*)
FROM
     "rpt_Transaction"
 WHERE
     DATE(TransStartDT) IN (SELECT DATE(MIN("TransStartDT")) as min_TransStartDT FROM "rpt_Transaction")

I received an error saying the query is taking too long to run and therefore was killed internally.

I decided to use a INNER JOIN to see if it works:
SELECT
     COUNT("T01"."TransactionID") 
FROM
     "rpt_Transaction" "T01"   INNER JOIN
          (SELECT DATE(MIN("TransStartDT")) as TransStartDT FROM "rpt_Transaction")  "T02"
    ON DATE("T01"."TransStartDT") = "T02"."TransStartDT"

I used tables aliases. The error message I get is " Only SELECT queries are allowed".

The top two queries work on a SQL Server and Oracle environment. May be not the best in terms of run time but they do work.

Any suggestions on how to build a valid SQL query for the above requirement?

Thanks
Sunil

      • Sticky Posts

      • Announcing Zoho Analytics 6.0 Beta!

        We are delighted to open up the next major version, Zoho Analytics 6.0 Beta! The new version comes packed with a wide range of functionalities for all persona, namely business users, data analysts, data engineers, and data scientists. Zoho Analytics team
      • What's New in Zoho Analytics - August 2024

        Hello Users! We are back with the latest updates and enhancements made to Zoho Analytics. Keep reading to learn more about them. Connect to the data hosted in the cloud without allow-listing the IP addresses Utilize Zoho Databridge to connect to the data
      • We are coming to your city! Zoho Analytics Community Meetup

        Hello, business leaders and data enthusiasts! We are delighted to announce that registrations are now open for the ZUG meetups, and we can't wait for you to be a part of them. Our in-house analytics experts are geared up to lead discussions on constructing
      • Zoho Analytics: 2021 Look Back

        As we start a new year in 2022, here's some of our top moments from 2021. Zoho Analytics in 2021
      • [Customer Talk] PREMO Group's Analyst Interview at Zoho Day 2022

        Premo Group, a 50 year old Spanish Manufacturing Company, has been our long-standing customer with #ZohoAnalytics. They've been using our platform for their end-to-end, unified business analytics solution.  Hear more from Claudio Cabeza, Director at PREMO