[SQL] Nested selects

2009-04-07 Thread Glenn Maynard
I'm deriving high scores from two tables: one containing data for each time a user played (rounds), and one containing a list of stages: CREATE TABLE stage (id SERIAL NOT NULL PRIMARY KEY, name VARCHAR); CREATE TABLE round (id SERIAL NOT NULL PRIMARY KEY, score REAL, stage_id INTEGER REFERENCES st

[SQL] changing multiple pk's in one update

2009-04-07 Thread Stuart McGraw
Hello all, I have a table with a primary key column that contains sequential numbers. Sometimes I need to shift them all up or down by a fixed amount. For example, if I have four rows with primary keys, 2, 3, 4, 5, I might want to shift them down by 1 by doing: UPDATE mytable SET id=id-1 (