Re: [SQL] Grouping Too Closely

2005-06-24 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > This doesn't give me quite what I'm looking for because I need there > to be only one of each possible value of seq2 to be returned for each > value of fkey. Then perhaps just: SELECT fkey, seq2, min(seq1) FROM my_table WHERE seq2 > 2 GROUP BY fk

Re: [SQL] Grouping Too Closely

2005-06-24 Thread Thomas F. O'Connell
This doesn't give me quite what I'm looking for because I need there to be only one of each possible value of seq2 to be returned for each value of fkey. -- Thomas F. O'Connell Co-Founder, Information Architect Sitening, LLC Strategic Open Source: Open Your i™ http://www.sitening.com/ 110 3

Re: [SQL] Grouping Too Closely

2005-06-24 Thread Greg Sabino Mullane
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 > What I'd like to be able to do is select all records corresponding to > the minimum value of seq1 for each value of seq2 corresponding to a > given fkey (with a lower bound on the value of seq2). I'm not sure how uid figures in, but would this do

Re: [SQL] Grouping Too Closely

2005-06-23 Thread Russell Simpkins
I'm not sure if this is the best thing to do in all occasions, but I have found a great speed increase using unions over group by. select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 = ( select min(seq1) from mytable); union select fkey, uid, seq2 from mytable where seq2 > 2 and seq1 =

[SQL] Grouping Too Closely

2005-06-23 Thread Thomas F. O'Connell
I have a table that looks like this:CREATE TABLE my_table (    pkey serial PRIMARY KEY,    fkey int NOT NULL REFERENCES my_other_table( pkey ),    uid int NOT NULL REFERENCES user( pkey ),    seq1 int,    seq2 int);Basically, for each fkey that exists in my_table, there is a sequence represented by