For one of our Vendor based SQL server database, they have created certain views for users to query. Since i am new to SQL querying, please help me understand the below format of SQL and how can i tune it up further as it runs over hours. I will try to get a repro, but for now, let me know if below can help:-
SELECT TABLE1.ID ABC TABLE1.COL1 XYZ TABLE1.COL2 ASD TABLE1.COL3 TABLE1.COL4 FROM TABLE1,TABLE2,TABLE3 WHERE TABLE2.ID=TABLE1.ID AND TABLE2.COLUMN1='Data' AND TABLE3.ID=TABLE1.ID AND TABLE3.COLUMN2='Value' AND TABLE1.COL1=CAST('20190914' as DATE) AND DATEPART(hour,TABLE1.COL1) BETWEEEN 1 AND 2
For Table1 there is no CI, we just have Unique NON CI as PK
TABLE 2 and TABLE 3 also does not have any CI, they both have Unique non CI on both ID and datetime column
TABLE1.COL1 is a
Above query is run multiple times in 12 batches a day for different date range in
between clause to collect data between 24 hours, like 0-1, 1-2, 2-3 , 3-4 .... 21-22,23-24
Is there a better way to perform above run?