Skip to content
Advertisement

SQL: Select certain rows with window functions in MySQL/MariaDB

My problem can be simplified to the following example:

Now I’m looking for an sql statement which selects all rows (ordered by dfrom) having a dfrom not between the dfrom and dto of any previously selected row, possibly using window functions to get informations on other rows, like this:

resulting in:

Can anyone give me the necessary sql statement?

Advertisement

Answer

I think the simplest approach is not exists:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement