Re: [SQL] Most efficient way to hard-sort records

2007-02-13 Thread Michael Glaesemann
On May 6, 2006, at 17:13 , Miroslav Šulc wrote: I have a table with cca 100,000 records. I need to hard-sort the records by a key from second table. By hard-sorting I mean storing position of each row in the main table. Here is what my tables look like: main_table: id, name, position key_tab

Re: [SQL] Most efficient way to hard-sort records

2006-05-09 Thread Miroslav Šulc
Hi PFC, the generate_series() seems to be the right thing I need in my scenario but I didn't figure out how to create a SELECT stattement that will contain sorted main_table.id in first column and generated series in second column which I would use to update the main_table.position. Is it possible

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread PFC
Another version along that line ? # create sequence counterseq start 1; -- (set/reset whenever a counter is needed) # select main_table.*, nextval('counterseq') as position2 into sorted_main_table from main_table, keytable where main_table.id = keytable.main_table_id order by value

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread Ben K.
CREATE TABLE sorted (order_no SERIAL PRIMARY KEY, other columns...) INSERT INTO sorted (columns) SELECT * FROM main_table INNER JOIN key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER BY value SELECT The SERIAL will automatically generate the order_no you wa

Re: [SQL] Most efficient way to hard-sort records

2006-05-07 Thread PFC
Is it possible to do this : CREATE TABLE sorted (order_no SERIAL PRIMARY KEY, other columns...) INSERT INTO sorted (columns) SELECT * FROM main_table INNER JOIN key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER BY value SELECT The SERIAL will automat

Re: [SQL] Most efficient way to hard-sort records

2006-05-06 Thread Ben K.
main_table: id, name, position key_table: id, main_table_id, key, value Here is how I need to sort the records: SELECT * FROM main_table INNER JOIN key_table ON main_table.id = key_table.main_table_id WHERE key = 'param' ORDER BY value I currently collect all ids from main_table in sorted order

Re: [SQL] Most efficient way to hard-sort records

2006-05-06 Thread Markus Schaber
Hi, Miroslav, Miroslav Šulc schrieb: > I have a table with cca 100,000 records. I need to hard-sort the records > by a key from second table. By hard-sorting I mean storing position of > each row in the main table. Here is what my tables look like: > > main_table: id, name, position > key_table:

[SQL] Most efficient way to hard-sort records

2006-05-06 Thread Miroslav Šulc
Hello, I have a table with cca 100,000 records. I need to hard-sort the records by a key from second table. By hard-sorting I mean storing position of each row in the main table. Here is what my tables look like: main_table: id, name, position key_table: id, main_table_id, key, value Here is how