[GENERAL] sql question

2005-03-13 Thread Steven Verhoeven
Hi all My table definition :    id | fref  | mref --+---+--   1   | 23    |   25   2   | 24    |   28   3   | 25    |   31   4   | 26    |   34 My problem : i need a query that results in this :    id |    ref --+--   1   | 23     1

[GENERAL] sql question

2005-03-13 Thread Steven Verhoeven
My table definition : id | fref | mref --+---+-- 1 | 23| 25 2 | 24| 28 3 | 25| 31 4 | 26| 34 i need a query that results in this : id |ref --+-- 1 | 23 1 | 25 2 | 24 2 | 28

[GENERAL] SQL Question

2005-04-15 Thread Alex
Hi, i have a table ProdId | LastUpdate ---+ 100| 2005-04-01 100| 2005-03-01 100| 2005-02-01 200| 2005-04-01 200| 2005-03-01 200| 2005-02-01 - How can i select only the newest record for each ProdId ? 100| 2005-04-01 200| 2005-04-01 - How can i select

[GENERAL] SQL question.

2005-06-01 Thread FC
Hello SQL Aces ! I want to do a select on a table distinct on linkid and sorted by date. I have try this SELECT DISTINCT ON (linkid) * FROM all_links WHERE uid='2' AND DATE_TRUNC('day',read_date) = DATE_TRUNC('day', TIMESTAMP '2005-06-01') ORDER BY linkid, read_date; With this req

[GENERAL] SQL question

2004-11-06 Thread Uwe C. Schroeder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Here's a question for the SQL guru's out there, which I've been trying to solve for the last couple of hours. There's got to be a solution to this, but somehow I can't find it. Tables: table1 ( uid int PK, uname varchar(64) ) tabl

[GENERAL] SQL question

2008-03-28 Thread kevin kempter
Hi List; I have a table that has 3 date columns : create table xyz ( xyz_id integer, date1 timestamp, date2 timestamp, date3 timestamp ) I want to select in a query the xyz_id and the max date column for each row something like : create table temp2 as select xyz_id (max date?) where .

[GENERAL] SQL Question

1999-03-10 Thread Matthew
I am using RH5.2 / Postgre 6.3.2 I need a query that has a having clause. In 6.3.2 it says that having is not supported yet. I looked at the changes in 6.4 and it appears that 6.4.2 supports this. Is this true? Also I have found 6.4.2 rpms but no data rpm so now when I try to use psql it say

[GENERAL] sql question

1999-11-17 Thread Herbert Liechti
I have a sql problem which I can't solve. The following table is defined create table AdressGroup ( AdrGroup_Id INTEGER NOT NULL DEFAULT NEXTVAL('adrverw_id_seq'), ZeitDATETIME NOT NULL, Group_IdI

[GENERAL] sql question

2001-05-14 Thread u95886230
Please help, I am trying to write an SQL statement but with no success as I am just starting out with sql. I have a table with 3 columns: Account# ,OrderType and date example of data: Account#¦ Ordertype ¦ Date 1 ¦ A ¦ April 1 ¦ B ¦ May 1

Re: [GENERAL] sql question

2005-03-13 Thread Vincent Hikida
: [GENERAL] sql question Hi all My table definition :   id | fref  | mref--+---+--  1   | 23    |   25  2   | 24    |   28  3   | 25    |   31  4   | 26    |   34My problem : i need a query that results in this :   id |    ref

Re: [GENERAL] sql question

2005-03-13 Thread Russell Smith
On Fri, 11 Mar 2005 11:36 pm, Steven Verhoeven wrote: > Hi all > > My table definition : > >id | fref | mref > --+---+-- > 1 | 23| 25 > 2 | 24| 28 > 3 | 25| 31 > 4 | 26| 34 > > My problem : > i need a query that

Re: [GENERAL] sql question

2005-03-13 Thread Klint Gore
On Fri, 11 Mar 2005 13:36:17 +0100, Steven Verhoeven <[EMAIL PROTECTED]> wrote: > Hi all > > My table definition : > >id | fref | mref > --+---+-- > 1 | 23| 25 > 2 | 24| 28 > 3 | 25| 31 > 4 | 26| 34 > > My probl

Re: [GENERAL] sql question

2005-03-13 Thread George Essig
On Fri, 11 Mar 2005 13:26:07 +0100, Steven Verhoeven <[EMAIL PROTECTED]> wrote: > My table definition : > >id | fref | mref > --+---+-- > 1 | 23| 25 > 2 | 24| 28 > 3 | 25| 31 > 4 | 26| 34 > > i need a query that

Re: [GENERAL] sql question

2005-03-14 Thread Ragnar Hafstað
On Sun, 2005-03-13 at 23:13 -0600, George Essig wrote: > On Fri, 11 Mar 2005 13:26:07 +0100, Steven Verhoeven > <[EMAIL PROTECTED]> wrote: > [snip problem] > select id, fref as ref from my_table > union > select id, mref as ref from my_table; union ALL (see other replies) gnari

Re: [GENERAL] sql question

2005-03-14 Thread Chris Travers
Steven Verhoeven wrote: Hi all My table definition : id | fref | mref --+---+-- 1 | 23| 25 2 | 24| 28 3 | 25| 31 4 | 26| 34 My problem : i need a query that results in this : id |ref --+-- 1 |

Re: [GENERAL] SQL Question

2005-04-15 Thread Thomas Kellerer
On 15.04.2005 13:58 Alex wrote: > Hi, > > i have a table > > ProdId | LastUpdate > ---+ > 100| 2005-04-01 > 100| 2005-03-01 > 100| 2005-02-01 > 200| 2005-04-01 > 200| 2005-03-01 > 200| 2005-02-01 > > - How can i select only the newest record for each Prod

Re: [GENERAL] SQL Question

2005-04-15 Thread GIROIRE, Nicolas (COFRAMI)
from test."tableProd" t where u."ProdId" = t."ProdId") -Message d'origine- De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] la part de Alex Envoyé : vendredi 15 avril 2005 13:59 À : pgsql-general@postgresql.org Objet : [GENERAL] SQL Question

Re: [GENERAL] SQL Question

2005-04-15 Thread Richard Huxton
GIROIRE, Nicolas (COFRAMI) wrote: For the first request (How can i select only the newest record for each ProdId ?), you can do : select * from test."tableProd" u where u."LastUpdate" = (select max(t."LastUpdate") from test."tableProd" t where u."ProdId" = t."ProdId") Although this onl

Re: [GENERAL] SQL Question

2005-04-15 Thread GIROIRE, Nicolas (COFRAMI)
005 15:42 À : GIROIRE, Nicolas (COFRAMI) Cc : Alex; pgsql-general@postgresql.org Objet : Re: [GENERAL] SQL Question GIROIRE, Nicolas (COFRAMI) wrote: > For the first request (How can i select only the newest record for each > ProdId ?), you can do : > > select * from test."tableProd&

Re: [GENERAL] SQL Question

2005-04-15 Thread jday
select max(lastupdate),prodid from tablename group by prodid -Original Message- From: Thomas Kellerer <[EMAIL PROTECTED]> Subj: Re: [GENERAL] SQL Question Date: Fri Apr 15, 2005 7:24 am Size: 621 bytes To: pgsql-general@postgresql.org On 15.04.2005 13:58 Alex wrote: > H

Re: [GENERAL] SQL Question

2005-04-15 Thread Thomas Kellerer
[EMAIL PROTECTED] wrote on 15.04.2005 16:42: select max(lastupdate),prodid from tablename group by prodid Even better :) Thomas ---(end of broadcast)--- TIP 8: explain analyze is your friend

Re: [GENERAL] SQL Question

2005-04-15 Thread Bruno Wolff III
On Fri, Apr 15, 2005 at 21:58:31 +1000, Alex <[EMAIL PROTECTED]> wrote: > Hi, > > i have a table > > ProdId | LastUpdate > ---+ > 100| 2005-04-01 > 100| 2005-03-01 > 100| 2005-02-01 > 200| 2005-04-01 > 200| 2005-03-01 > 200| 2005-02-01 > > - How can i se

Re: [GENERAL] SQL Question

2005-04-16 Thread Julian Scarfe
From: "Alex" <[EMAIL PROTECTED]> - How can i select only the newest record for each ProdId ? 100| 2005-04-01 200| 2005-04-01 DISTINCT ON was made for this and on the similar tables I have performs rather more efficiently than using a subquery. select distinct on (ProdId) ProdId , LastUpda

Re: [GENERAL] SQL Question

2005-04-17 Thread Alex
Julian Scarfe wrote: From: "Alex" <[EMAIL PROTECTED]> - How can i select only the newest record for each ProdId ? 100| 2005-04-01 200| 2005-04-01 DISTINCT ON was made for this and on the similar tables I have performs rather more efficiently than using a subquery. select distinct on (Prod

Re: [GENERAL] SQL question.

2005-06-01 Thread Jim Buttafuoco
nal Message --- From: FC <[EMAIL PROTECTED]> To: pgsql-general@postgresql.org Sent: Wed, 1 Jun 2005 16:40:48 +0200 Subject: [GENERAL] SQL question. > Hello SQL Aces ! > > I want to do a select on a table distinct on linkid and sorted by > date. I have try this > > SEL

Re: [GENERAL] SQL question.

2005-06-01 Thread Martijn van Oosterhout
On Wed, Jun 01, 2005 at 04:40:48PM +0200, FC wrote: > > Hello SQL Aces ! > > I want to do a select on a table distinct on linkid and sorted by > date. I have try this How about a subquery?: SELECT * FROM ( SELECT DISTINCT ON (linkid) * FROM all_links WHERE uid='2' AND DATE_TRUNC('day',rea

Re: [GENERAL] SQL question.

2005-06-01 Thread FC
ay',TIMESTAMP '2005-06-01') ORDER BY linkid ) A ORDER BY read_date DESC limit 100 -- Original Message --- From: FC <[EMAIL PROTECTED]> To: pgsql-general@postgresql.org Sent: Wed, 1 Jun 2005 16:40:48 +0200 Subject: [GENERAL] SQL question. Hello SQL Aces !

Re: [GENERAL] [SQL] question

2005-08-29 Thread Matt A.
The issue has been solved thanks to a custom nullif_int() function. Which if anyone has the same issue, it was solved with... CREATE FUNCTION nullif_int(text) RETURNS integer AS 'SELECT nullif($1,)::int;' LANGUAGE SQL; SELECTS were not the issue; INSERT INTO a non-text column was the issue.

Re: [GENERAL] SQL question

2004-11-06 Thread Uwe C. Schroeder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 If someone knows this it would be great - because I'm still curious how to solve it. However I just remodelled my db structure to eliminate the problem (basically I pulled the several tables into one since each of the table2/table3 tables only has

Re: [GENERAL] SQL question

2004-11-06 Thread Vincent Hikida
l I can do for tonight. Vincent - Original Message - From: "Uwe C. Schroeder" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Saturday, November 06, 2004 3:13 PM Subject: [GENERAL] SQL question -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Here's a questio

Re: [GENERAL] SQL question

2004-11-07 Thread Greg Stark
"Uwe C. Schroeder" <[EMAIL PROTECTED]> writes: > Here's a question for the SQL guru's out there, which I've been trying to > solve for the last couple of hours. There's got to be a solution to this, but > somehow I can't find it. > > Tables: > > table1 ( > uid int PK, > uname var

Re: [GENERAL] SQL question

2004-11-08 Thread Uwe C. Schroeder
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Thanks for your answers Greg & Vincent. Although I solved the problem by a change of schema - I'm happy that I have something to digest I didn't know before. One never learns enough ... U.C. On Saturday 06 November 2004 03:13 pm, Uwe C. Schroeder

Re: [GENERAL] SQL question

2008-03-28 Thread Adam Rich
> I have a table that has 3 date columns : > > create table xyz ( > xyz_id integer, > date1 timestamp, > date2 timestamp, > date3 timestamp > ) > > > I want to select in a query the xyz_id and the max date column for > each row > something like : > create table temp2 as select xyz_id (max

[GENERAL] SQL Question - "Recursion"

2008-08-26 Thread ktr73
Hi - Was wondering if anyone could help / had some thoughts. I am building a model for a client, and right now doing customer attrition modeling. Basically, the number of customers in this period is equal to: Beg # Customers + customers added this period - attrition Ending # Customers Obviousl

RE: [GENERAL] SQL Question

1999-03-10 Thread Michael Davis
PROTECTED] Subject: [GENERAL] SQL Question I am using RH5.2 / Postgre 6.3.2 I need a query that has a having clause. In 6.3.2 it says that having is not supported yet. I looked at the changes in 6.4 and it appears that 6.4.2 supports this. Is this true? A

Re: [GENERAL] sql question

1999-01-16 Thread Herbert Liechti
[EMAIL PROTECTED] wrote: > > > SELECT * FROM adressGroup > > > WHERE Group_Id = 6 > > > AND EXISTS( SELECT AdrGroup_Id FROM adressGroup ag_alias > > > WHERE adressGroup.AdrGroup_Id = ag_alias.AdrGroup_Id > > > GROUP BY AdrGroup_Id HAVING COUNT(*) = 1); > >

Re: [GENERAL] sql question

2000-07-12 Thread Ross J. Reedstrom
On Wed, Jul 12, 2000 at 05:33:09PM -0500, Travis Bauer wrote: > > Let's say I have a table t1 with two fields, x and y. How do I write an > sql statement like: > > select x if y>1 else 0 from t1; SELECT CASE WHEN y>1 THEN x ELSE 0 END FROM t1; >From page 33 of Bruce's book, at: http://www.po

Re: [GENERAL] sql question

2000-07-13 Thread Travis Bauer
Thanks, Now that you mention it, I even remember reading it in the book! Travis Bauer | CS Grad Student | IU |www.cs.indiana.edu/~trbauer On Wed, 12 Jul 2000, Ross J

Re: [NOVICE] [GENERAL] sql question

2005-03-13 Thread Vincent Hikida
13, 2005 6:34 PM Subject: Re: [NOVICE] [GENERAL] sql question SELECT  t1.id   ,  t1.fref     FROM t1 UNION ALL SELECT t2.id   , t2.mref FROM t2   - Original Message - From: Steven Verhoeven To: pgsql-general

Re: [GENERAL] SQL Question - "Recursion"

2008-08-26 Thread Guy Rouillier
ktr73 wrote: Hi - Was wondering if anyone could help / had some thoughts. I am building a model for a client, and right now doing customer attrition modeling. Basically, the number of customers in this period is equal to: Beg # Customers + customers added this period - attrition Ending # Cust

[GENERAL] SQL Question - Using Group By

2007-02-25 Thread Mike
Hi, I have a question about using Group By. On a table like this: Type (varchar) | Active (boolean) Type One | False Type Two | True Type One | True Type Fifty | Flase Typ

Re: [GENERAL] [SQL] Question on indexes

2005-12-19 Thread Alvaro Herrera
Emil Rachovsky wrote: > > Hi, > Can anyone show me a simple way of creating an index > in PostGre like that: > create index indName on someTable(someIntColumn DESC) > ? Not using that particular syntax, but you can do that if you create the appropiate operator classes. Note that if you want to u

[GENERAL] SQL question re aggregates & joins

2010-01-28 Thread Scott Ribe
OK, this does not work: select max(t1."When"), t1."Pt_Id", t2."DateOfBirth" from "PtStaffAccess" t1, "Person" t2 where t1."Pt_Id" = t2.id group by t1."Pt_Id"; But this does: select max(t1."When"), t1."Pt_Id", min(t2."DateOfBirth") from "PtStaffAccess" t1, "Person" t2 where t1."Pt_Id" = t2.id gro

Re: [GENERAL] SQL Question - Using Group By

2007-02-25 Thread [EMAIL PROTECTED]
You could use COUNT() in conjunction with NULLIF: select "Type", count(nullif("Active", false)) as "Active Count", count(nullif("Active", true)) as "Inactive Count", 100 * count(nullif("Active", false)) / count(*) as "Active Percent" from table_name group by "Type" On Feb 23, 2:50 pm, "Mike" <[E

Re: [GENERAL] SQL Question - Using Group By

2007-02-25 Thread Mike
Thank you! Exactly what I needed. Mike On Feb 23, 4:42 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > You could use COUNT() in conjunction with NULLIF: > > select "Type", > count(nullif("Active", false)) as "Active Count", > count(nullif("Active", true)) as "Inactive Count", > 100 * count(nu

Re: [GENERAL] SQL Question - Using Group By

2007-02-25 Thread Tomas Vondra
Hi, I have a question about using Group By. On a table like this: Type (varchar) | Active (boolean) Type One | False Type Two | True Type One | True Type Fifty | Flase

Re: [GENERAL] SQL Question - Using Group By

2007-02-26 Thread Alban Hertroys
[EMAIL PROTECTED] wrote: > You could use COUNT() in conjunction with NULLIF: > > select "Type", > count(nullif("Active", false)) as "Active Count", > count(nullif("Active", true)) as "Inactive Count", > 100 * count(nullif("Active", false)) / count(*) as "Active Percent" > from table_name group by

[GENERAL] SQL question: checking all required items

2007-08-10 Thread Raymond O'Donnell
Hi all, Given the following tables - create table people ( person_id text primary key, person_name text, [...etc...] ); create table items ( item_id text primary key, item_name text, is_required boolean, [...etc...] ); create table items_for_people ( p

Re: [GENERAL] SQL question re aggregates & joins

2010-01-28 Thread Thom Brown
On 28 January 2010 21:32, Scott Ribe wrote: > OK, this does not work: > > select max(t1."When"), t1."Pt_Id", t2."DateOfBirth" > from "PtStaffAccess" t1, "Person" t2 > where t1."Pt_Id" = t2.id > group by t1."Pt_Id"; > > But this does: > > select max(t1."When"), t1."Pt_Id", min(t2."DateOfBirth") >

Re: [GENERAL] SQL question re aggregates & joins

2010-01-28 Thread Scott Ribe
> You can't include an aggregate in the select if you don't group by > non-aggregates, so it should be: > > select max(t1."When"), t1."Pt_Id", t2."DateOfBirth" > from "PtStaffAccess" t1, "Person" t2 > where t1."Pt_Id" = t2.id > group by t1."Pt_Id", t2."DateOfBirth"; I was aware that I could alter

Re: [GENERAL] SQL question re aggregates & joins

2010-01-28 Thread Dann Corbit
> -Original Message- > From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general- > ow...@postgresql.org] On Behalf Of Scott Ribe > Sent: Thursday, January 28, 2010 2:10 PM > To: Thom Brown > Cc: pgsql-general > Subject: Re: [GENERAL] SQL question re aggregat

Re: [GENERAL] SQL question re aggregates & joins

2010-01-28 Thread Tom Lane
Scott Ribe writes: > Given that t2.id is the primary key, grouping by any other column of t2 is > really redundant. I know *what* SQL won't allow me to do, I'm interested in > knowing if there's some reason *why* other than historical... SQL92 says so. More recent versions of the SQL spec descri

Re: [GENERAL] SQL question - problem with INTERSECT

2000-10-31 Thread Igor Roboul
On Mon, Oct 30, 2000 at 07:59:06PM -0500, Keith L. Musser wrote: > "(SELECT messages.msgid FROM messages, subject_index WHERE > ((subject_index.word='Hello' or subject_index.word='There') and > (subject_index.msgid = messages.msgid)) > GROUP BY messages.msgid HAVING count(messages.msgid)=2) > INTE

Re: [GENERAL] SQL question - problem with INTERSECT

2000-11-01 Thread Keith L. Musser
d 'Jones'.) So I cannot remove either having clause without changing the meaning. What I would really like to know is why INTERSECT does not allow this. If I understand that, maybe I can figure out how to get what I need. -Original Message- From: Igor Roboul <[EMAIL PROTEC

Re: [GENERAL] SQL question - problem with INTERSECT

2000-11-02 Thread hubert depesz lubaczewski
On Thu, Nov 02, 2000 at 06:50:07AM -0500, Keith L. Musser wrote: > > upper(a.word) = 'JIM' or upper(a.word) = 'JONES' > > upper(s.word) = 'HELLO' or upper(s.word) = 'THERE' > Interesting possibility. Unfortunately, the outer select ends up being > a sequential scan over the entire messages table,

Re: [GENERAL] SQL question: checking all required items

2007-08-10 Thread Scott Marlowe
On 8/10/07, Raymond O'Donnell <[EMAIL PROTECTED]> wrote: > - how can I find those people who don't have _all_ of the items which > are marked "required"? > > In other words, how do I select those rows in "people" which don't have > a corresponding row in "items_for_people" for *each* row in "items"

Re: [GENERAL] SQL question: checking all required items

2007-08-10 Thread Raymond O'Donnell
On 10/08/2007 21:29, Scott Marlowe wrote: select table1.id from table1 where table1.id is not in (select id from table2); Duh! I should have thought of that thanks for that, and apologies for the stupidity (blame it on the glass of wine I had with dinner!). Ray. --

Re: [GENERAL] SQL question: checking all required items

2007-08-10 Thread Scott Marlowe
On 8/10/07, Raymond O'Donnell <[EMAIL PROTECTED]> wrote: > On 10/08/2007 21:29, Scott Marlowe wrote: > > > > select table1.id from table1 where table1.id is not in (select id from > > table2); > > Duh! I should have thought of that thanks for that, and apologies > for the stupidity (blame it o

Re: [GENERAL] SQL question: checking all required items

2007-08-11 Thread Raymond O'Donnell
On 10/08/2007 22:03, Carlos Ortíz wrote: Select * from people where person_id in ( Select person_ID from Items_for_people group by Person_id Having Count(*) = ( Select count(*) from Items Where is_required = true)) That seems to work fine! I'd only change "having count(*) = .

Re: [GENERAL] SQL question: checking all required items

2007-08-11 Thread Raymond O'Donnell
On 10/08/2007 21:42, Scott Marlowe wrote: Show us the query when you're done, I'm sure there are enough folks who'd like to see your solution. Here's what I came up with: select distinct ip.person_id from items_for_people ip where exists ( ( select item_id from items where

Re: [GENERAL] SQL question: checking all required items

2007-08-17 Thread Carlos Ortíz
#x27;s not correct, but I'm new in postgresql. In sql server it's ok) De: [EMAIL PROTECTED] en nombre de Raymond O'Donnell Enviado el: Vie 10/08/2007 03:07 p.m. Para: 'PostgreSQL' Asunto: [GENERAL] SQL question: checking all required it

[GENERAL] SQL Question - Group By and % results per row

2007-03-15 Thread Mike
I have a SQL statement that uses group-by to generate reports as such: GroupFieldClicks --- Page 1 50 Page 2 20 Page 3 30 Now, as an added field, I also want it to tell me what percent of total clicks each row represe

Re: [GENERAL] SQL Question - Group By and % results per row

2007-03-15 Thread Bruno Wolff III
On Mon, Mar 12, 2007 at 12:53:11 -0700, Mike <[EMAIL PROTECTED]> wrote: > > How do I get access to the total of all clicks on per row basis so I > can divide it? The only solution that comes to my mind is create a > subquery that does a (select count(*) from... where... ) of the > original group

[GENERAL] sql question; checks if data already exists before inserted

2006-06-21 Thread nuno
hi, there. i'm trying to write a SQL statement which does the following things. 1. checks if data already exists in the database 2. if not, insert data into database otherwise skip. for example, i'd like to insert a student called 'Michael Jordan' whose ID is 'JORDANMICHAEL' only if the id, 'JORD

Re: [GENERAL] sql question; checks if data already exists before

2006-06-23 Thread Kostas Maistrelis
nuno wrote: >hi, there. i'm trying to write a SQL statement which does the following >things. > >1. checks if data already exists in the database >2. if not, insert data into database otherwise skip. > > > Check this thread : http://archives.postgresql.org/pgsql-general/2005-10/msg01787.php

[GENERAL] SQL-question: returning the id of an insert querry

2003-11-09 Thread Andreas Fromm
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, Im building an user database with many tables keeping the data for the Address, Phone numbers, etc which are referenced by a table where I keep the single users. My question is, how do I get the "Id"-value of a newly inserted address to store it i

Re: [GENERAL] sql question; checks if data already exists before inserted

2006-06-22 Thread Martijn van Oosterhout
On Wed, Jun 21, 2006 at 10:59:42PM -0700, nuno wrote: > insert into student (studentid, fname, lname) > select 'JORDANMICHAEL', 'Michale', 'Jordan' from student where > studentid not in > (select studentid from student); > > however, this does not seem to work. it does not insert data even if it >

Re: [GENERAL] sql question; checks if data already exists before inserted

2006-06-22 Thread Guy Rouillier
nuno wrote: > hi, there. i'm trying to write a SQL statement which does the > following things. > > 1. checks if data already exists in the database > 2. if not, insert data into database otherwise skip. > > for example, i'd like to insert a student called 'Michael Jordan' > whose ID is 'JORDANM

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-09 Thread Martijn van Oosterhout
After you've done the insert on the address table, you can use currval('address_id_seq') (or equivalent) to get the ID. Ofcourse you have to have used nextval() for the original insert. Hope this helps, On Sun, Nov 09, 2003 at 11:29:49AM +0100, Andreas Fromm wrote: > Hi, > > Im building an user

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-09 Thread Andreas Fromm
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Martijn van Oosterhout wrote: > After you've done the insert on the address table, you can use > currval('address_id_seq') (or equivalent) to get the ID. Ofcourse you have > to have used nextval() for the original insert. > > Hope this helps, > ..goi

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-09 Thread Scott Chapman
On Sunday 09 November 2003 03:13, Martijn van Oosterhout wrote: > After you've done the insert on the address table, you can use > currval('address_id_seq') (or equivalent) to get the ID. Ofcourse you > have to have used nextval() for the original insert. What if someone else inserts another addre

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-09 Thread Doug McNaught
Scott Chapman <[EMAIL PROTECTED]> writes: > On Sunday 09 November 2003 03:13, Martijn van Oosterhout wrote: > > After you've done the insert on the address table, you can use > > currval('address_id_seq') (or equivalent) to get the ID. Ofcourse you > > have to have used nextval() for the original

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-09 Thread Alvaro Herrera
On Sun, Nov 09, 2003 at 10:26:51AM -0800, Scott Chapman wrote: > On Sunday 09 November 2003 03:13, Martijn van Oosterhout wrote: > > After you've done the insert on the address table, you can use > > currval('address_id_seq') (or equivalent) to get the ID. Ofcourse you > > have to have used nextval

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-10 Thread Alvaro Herrera
On Mon, Nov 10, 2003 at 08:09:29AM -0800, Scott Chapman wrote: > Chronological events here: > > X inserts a new record into A. > Y inserts a new record into A. > X fetches currval of the SA. What value does X get in this case, the one > from X's insert or Y's? X's. -- Alvaro Herrera () "¿Qué

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-10 Thread Scott Chapman
On Monday 10 November 2003 08:23, David Green wrote: > Are X & Y two different connections? > If you execute 2 statements on the same connection and then get > currval() it will give the last generated id. > > Ex. > On 1 connection: > INSERT INTO A (fld) VALUES (val); -- id generated = 1 > INSERT I

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-10 Thread Kathy Zhu
I saw this method of Statement class in jdbc. Will the return int contain the autogenerated key value ?? public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException thanks, kathy Scott Chapman wrote: > On Monday 10 November 2003 08

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-12 Thread Andrew Sullivan
On Mon, Nov 10, 2003 at 08:56:03AM -0800, Scott Chapman wrote: > I talked with the author or SQLObject about this recently and I thnk > he's implementing this correctly, by querying the cursor for the last > OID?: That won't scale unless you index oid. And your tables will all need oids, which

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-12 Thread Greg Stark
"scott.marlowe" <[EMAIL PROTECTED]> writes: > select tablename.fieldname.currval; That syntax would be problematic, it would mean to select all rows from tablename and evaluate fieldname.currval for each one. Actually it's worse, it would be confused with schemas I think. The postgres-ish way t

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-12 Thread Doug McNaught
Scott Chapman <[EMAIL PROTECTED]> writes: > On Wednesday 12 November 2003 11:29, Doug McNaught wrote: > > Scott Chapman <[EMAIL PROTECTED]> writes: > > > It would be nice if PostgreSQL could return the primary key it > > > inserted with but that may not be a fool-proof solution either. Is > > > t

Re: [GENERAL] SQL-question: returning the id of an insert querry

2003-11-12 Thread Doug McNaught
Scott Chapman <[EMAIL PROTECTED]> writes: > It would be nice if PostgreSQL could return the primary key it inserted > with but that may not be a fool-proof solution either. Is there a nice > way to handle this situation? Write a database function that inserts the record and returns the primary