Re: [SQL] sql query question ?

2007-12-31 Thread Trilok Kumar
Dear Shane, Thanks for the reply and your observation about the word i have used. It is idle odometer reading. The actual Scenario is that the vehicle is taken by the driver. When he comes the next day. He is suppose to login again. Here i am trying to find out how much distance has the vehic

[SQL] Limit # of recs on inner join?

2007-12-31 Thread Josh
I want to limit the number of records returned by an inner join. Suppose I have a table of Books: book_id title And, a table of authors: book_id author_name Now, suppose I want to get book + author, but I only want one author for books with multiple authors. Traditionally, I'd do something

Re: [SQL] Limit # of recs on inner join?

2007-12-31 Thread Rodrigo E. De León Plicet
On Dec 31, 2007 1:52 PM, Josh <[EMAIL PROTECTED]> wrote: > Instead, I just want: > > 1 A Cat In The HatDr. Seuss SELECT books.book_id, books.title, (SELECT author_name FROM authors WHERE book_id = books.book_id LIMIT 1) AS author_name FROM books WH

Re: [SQL] Limit # of recs on inner join?

2007-12-31 Thread Richard Broersma Jr
SELECT DISTINCT ON ( B.book_id, B.title ) B.book_id, B.title, A.Author FROM Books AS B INNER JOIN Authors AS A ON A.book_id = B.book_id; --- On Mon, 12/31/07, Josh <[EMAIL PROTECTED]> wrote: > From: Josh <[EMAIL PROTECTED]> > Subject: [SQL] Limit # of recs on inner join? > To:

[SQL] Using rules to implement backward-compatible schema changes

2007-12-31 Thread Mario Becroft
Hi postgres experts, I have encountered what is, to me, a slightly tricky problem when using rules and I am in need of some help. I am using rules to simulate an old version of a database schema for backward-compatibility while migrating to a modified schema. For instance, there used to be a tab

Re: [SQL] Using rules to implement backward-compatible schema changes

2007-12-31 Thread Tom Lane
Mario Becroft <[EMAIL PROTECTED]> writes: > The problem is that when inserting to the view, default values do not > work as expected. You need to attach the defaults to the view, viz ALTER TABLE a ALTER COLUMN bar SET DEFAULT 5; This is considered a feature not a bug, since you might wan

Re: [SQL] Using rules to implement backward-compatible schema changes

2007-12-31 Thread Mario Becroft
Tom Lane <[EMAIL PROTECTED]> writes: > Mario Becroft <[EMAIL PROTECTED]> writes: >> The problem is that when inserting to the view, default values do not >> work as expected. > > You need to attach the defaults to the view, viz > > ALTER TABLE a ALTER COLUMN bar SET DEFAULT 5; > > This is co