0

I want to select all rows starting after a specific uuid, for example here is the data

+--------------------------------------+-----------+------------+
|                 uuid                 | divisi_id | divisionid |
+--------------------------------------+-----------+------------+
| b303a96b-2a03-4b5e-90a1-6b3631fc82af | BTT       |          3 |
| 8c4bf1b8-7477-42e4-affb-31bafa8648f1 | BTT       |          3 |
| 6639909d-74e1-4dec-a1f3-f70703c0b6c6 | BTT       |          3 |
| 1a1aa367-1467-4811-848d-694dbe98a5a8 | BTT       |          3 |
| e739b352-d952-4ec8-980e-a50180e18144 | BTT       |          3 |
+--------------------------------------+-----------+------------+

now, for example I have last uuid = 8c4bf1b8-7477-42e4-affb-31bafa8648f1 (the 2nd entry). how to select rows after that uuid? i have no idea about it.

Dariel Pratama
  • 1,607
  • 3
  • 18
  • 49
  • Please read http://meta.stackoverflow.com/questions/285551/why-may-i-not-upload-images-of-code-on-so-when-asking-a-question/285557 and the accepted answer –  Apr 27 '17 at 06:11
  • uuids have no natural ordering so there is no such thing as the uuid "after" another one –  Apr 27 '17 at 06:12
  • thank you @a_horse_with_no_name. I will convert the image to a text table. and so, there is no solution for my issue? – Dariel Pratama Apr 27 '17 at 06:14
  • please first edit your question to formatted text and define the sorting algorythm – Vao Tsun Apr 27 '17 at 07:32
  • `uuid`s [*have* an ordering, but it is rather a technical ordering](http://stackoverflow.com/questions/33549747/how-to-query-uuid-for-postgres) (and certainly have nothing to do with f.ex. "insertion order") -- your question's "after" implies that you want some row ordering. But in PostgreSQL, there is no default ordering (in fact, all other RDBMS also lack that, some just have a *de facto* ordering, which still shouldn't be relied upon). **In short**: if you have something to `ORDER BY` upon, your task is trivial, if you have no such thing, you cannot solve that at all. – pozs Apr 27 '17 at 07:59
  • there you go @VaoTsun – Dariel Pratama Apr 27 '17 at 08:17

1 Answers1

2

Try this

SELECT d1.* FROM
(SELECT Row_Number() over (order by id) AS RowIndex, * from tableName ) AS d1 
INNER JOIN 
(SELECT Row_Number() over (order by id) AS RowIndex, * from tableName) AS d2 
ON (d2.uuid  = '8c4bf1b8-7477-42e4-affb-31bafa8648f1' and d1.RowIndex > d2.RowIndex)

Hope you have primary key!!

If you don't have Primary key than

SELECT d1.* FROM
(SELECT Row_Number() over (order by (select null)) AS RowIndex, * from tableName) AS d1 
INNER JOIN 
(SELECT Row_Number() over (order by (select null)) AS RowIndex, * from tableName) AS d2 
ON (d2.uuid  = '8c4bf1b8-7477-42e4-affb-31bafa8648f1' and d1.RowIndex > d2.RowIndex)
Anurag Dadheech
  • 629
  • 1
  • 5
  • 14