This is a discussion on selecting un-ordered rows within the pgsql Novice forums, part of the PostgreSQL category; --> Hello, have enyone idea, how to select all rows, preceeding 'mary' (first two rows, but not LIMIT 2) name ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, have enyone idea, how to select all rows, preceeding 'mary' (first two rows, but not LIMIT 2) name date albert 2006-05-17 john 2006-05-17 mary 2006-05-17 benjamin 2006-05-17 carl 2006-05-17 alice 2006-05-17 thanks for help Dan ---------------------------(end of broadcast)--------------------------- TIP 5: don't forget to increase your free space map settings |
| ||||
| El día Tue, 16 May 2006 13:34:33 +0200 Du¨an PE¦L <pesl@asprkyjov.cz> escribió: > have enyone idea, how to select all rows, preceeding 'mary' > (first two rows, but not LIMIT 2) > > name date > albert 2006-05-17 > john 2006-05-17 > mary 2006-05-17 > benjamin 2006-05-17 > carl 2006-05-17 > alice 2006-05-17 You are implying that data is pre-ordered within the database, which IMHO is incorrect in any relational database. If "un-ordered" means for you that is ordered by date of insertion you might try adding a timestamp or serial column to your table and perform a select like: SELECT * FROM table ORDER BY tstamp LIMIT 2 If you do not want to add another column, you might try ordering by oid "SELECT * FROM table ORDER BY oid LIMIT 2", provided you created your table with oids (which I think is the default setting) but the result is not guaranteed for a long lived database because oids can roll-over. You may want to have a look at: http://www.postgresql.org/docs/8.1/s...ies-order.html http://www.postgresql.org/docs/8.1/s...ies-limit.html If you do not want to use limit you can use a WHERE clause instead. E.g. SELECT * FROM table WHERE tstamp < (SELECT tstamp FROM table WHERE name = 'Mary') Regards, -- Oscar ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |