I have a table tablename with columns col1-col10. Not every row has col4 populated, but every row has col1, col2, col3 populated. I want to get all {col1, col2, col3} tuples for when col4 satisfies a condition, then get all rows that match the tuple {col1, col2, col3} from tablename.
I have this query:
select t.*
from mytable t
where exists (
select 1
from mytable t1
where
t1.col1 = t.col1
and t1.col2 = t.col2
and t1.col3 = t.col3
and t1.col4 >= 1000
)
LIMIT 1000
The size of the table is very large so I have to add the limit. Due to the limit, for some {col1, col2, col3} not getting all rows in the result dataset. I want to then get all rows that match the tuple {col1, col2, col3} from tablename.
I don't mind have less {col1, col2, col3} tuples in my result, but I want complete information for the ones I do have.
How can I achieve that?
LIMIT
clause? – The Impaler