in Education by
I have a table historical_data ID Date column_a column_b 1 2011-10-01 a a1 1 2011-11-01 w w1 1 2011-09-01 a a1 2 2011-01-12 q q1 2 2011-02-01 d d1 3 2011-11-01 s s1 I need to retrieve the whole history of an id based on the date condition on any 1 row related to that ID. date>='2011-11-01' should get me ID Date column_a column_b 1 2011-10-01 a a1 1 2011-11-01 w w1 1 2011-09-01 a a1 3 2011-11-01 s s1 I am aware you can get this by using a CTE or a subquery like with selected_id as ( select id from historical_data where date>='2011-11-01' ) select hd.* from historical_data hd inner join selected_id si on hd.id = si.id or select * from historical_data where id in (select id from historical_data where date>='2011-11-01') In both these methods I have to query/scan the table ``historical_data``` twice. I have indexes on both id and date so it's not a problem right now, but as the table grows this may cause issues. The table above is a sample table, the table I have is about to touch 1TB in size with upwards of 600M rows. Is there any way to achieve this by only querying the table once? (I am using Snowflake) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Using QUALIFY: SELECT * FROM historical_data QUALIFY MAX(date) OVER(PARTITION BY id) >= '2011-11-01'::DATE;

Related questions

0 votes
    Which algorithm uses equality comparison on a key attribute with a primary index to retrieve a single ... Database Interview Questions and Answers for Freshers and Experience...
asked Oct 11, 2021 in Education by JackTerrance
0 votes
    The strategy can retrieve a single record if the equality condition is on a key; multiple records may ... Operation in section Query Processing Techniques of Database Management...
asked Oct 10, 2021 in Education by JackTerrance
0 votes
    I have this dataframe and trying to select the last n (=2) rows if the present value is True so I code as ... , I should select 50,40 Select the correct answer from above options...
asked Jan 8, 2022 in Education by JackTerrance
0 votes
    Department and store model. They are a one to one relationship. when I do the (Include) only some ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I have csv file and that looks like following. I want to remove all rows before one row values [ ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 14, 2022 in Education by JackTerrance
0 votes
    I am trying to adjust the row height based on the cell value. The operation have to run through ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 1, 2022 in Education by JackTerrance
0 votes
    Explain the relationship between man and environment historical Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    I'm working on Excel VBA macros and I want to retrieve data from a MS Access database (.accdb ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 11, 2022 in Education by JackTerrance
0 votes
    How could we retrieve a single value from data base using Groovy?...
asked Sep 25, 2021 in Technology by JackTerrance
0 votes
    This question already has answers here: How to reshape data from long to wide format (12 answers) Closed ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 5, 2022 in Education by JackTerrance
0 votes
    How do I transfer data from a worksheet to another based on a specific cell value? I tried several ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 22, 2022 in Education by JackTerrance
0 votes
    How do I transfer data from a worksheet to another based on a specific cell value? I tried several ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked May 7, 2022 in Education by JackTerrance
0 votes
    what i want : i have a config file where it contains some urls in .json file stored in asset ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 20, 2022 in Education by JackTerrance
0 votes
    Which of the following library is used to retrieve and acquire statistical data and metadata disseminated in ... Data-Science,Data-Science-Lifecycle,Applications-of-Data-Science...
asked Oct 30, 2021 in Education by JackTerrance
...