[SQL] pg, mysql comparison with "group by" clause

2005-10-11 Thread Rick Schumeyer
I'm not sure what I was thinking, but I tried the following query in pg: SELECT * FROM t GROUP BY state; pg returns an error. Mysql, OTOH, returns the first row for each state. (The first row with "AK", the first row with "PA", etc.) I'm no SQL expert, but it seems to me that the pg behavior

[SQL] question re. count, group by, and having

2005-10-11 Thread Rick Schumeyer
The following query returns an error (“column c does not exist”) in pg 8.0.3:   (The column ‘state’ is the two letter abbreviation for a US state)   -- get the number of rows for each state; list in descending order; include only states with at least 6 rows select state, count(state) a

[SQL] Help with multistage query

2005-09-07 Thread Rick Schumeyer
I have a perl script that issues a series of SQL statements to perform some queries.  The script works, but I believe there must be a more elegant way to do this.   The simplified queries look like this:   SELECT id FROM t1 WHERE condition1;   ;returns about 2k records which are stored

[SQL] simulating row ownership

2005-01-07 Thread Rick Schumeyer
I have a table where I want everyone to be able to be able to insert and select. But they should only be able to update and delete rows that they “own”.  The table has a column indicating the owner.   What is the best way to accomplish this?  I’m not real familiar with rules, but it see