I
I
IvanN7772021-11-08 18:36:02
SQL
IvanN777, 2021-11-08 18:36:02

How to compare two rows from the same table without additional join or from?

Suppose there are a number of conditions that limit the set to 5 - 10 rows
The table has a large data size
Select a row where status is OPEN, but if there is another row with status status - CLOSED
Where statusId is equal for two rows.
Is it possible to work with a selection of 5-10 rows and not join a huge table?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ruslan., 2021-11-08
@IvanN777

You can fill in the query result, these same 5-10 lines, into a temporary table and continue working with it. Then you don't have to join a large table.

S
Sergey Vodakov, 2021-11-08
@WaterSmith

Yes, make a selection and join it to itself.

I
Ipatiev, 2021-11-08
@Fockker

The question, as always, is stupid.
Sounds like "can you eat soup without a spoon?". And further in justification ridiculous fears.
You should not be afraid to "join a huge table" but learn how to optimize queries.
In this case, there is no problem with the join.
If it slows down, put the desired index, at least by statusId

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question