Re: Basic Query Question

From: Jude Lucien <jlucien(at)gmail(dot)com>
To: Ramy Abdel-Azim <ramy(dot)abdel-azim(at)startdatelabs(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Basic Query Question
Date: 2011-12-07 21:15:42
Message-ID: CAPRXF2o=pdsbQpC8txpfxFsoMF+sKz7E0XATA_f2+XPUPWDUVA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I've just realised why it may not be working - bike_id is not the
primary key of booking. booking_id is.

I was getting results, just not the correct ones. There are 23 bikes
of a certain model, two of which are booked on a certain date. My
query should then return 21 bike_id's.

Can I even do a join if booking.bike_id is not the primary key?

On 7 December 2011 21:02, Ramy Abdel-Azim
<ramy(dot)abdel-azim(at)startdatelabs(dot)com> wrote:
> i'm not sure but i think not being explicit about the join causes psql to
> try to join on ID.
>
> What are you getting? an error or an empty result set?
>
> I would think you should do the join explicitly like this:
>
> select bike.bike_id from bike  join booking on bike.bike_id =
> booking.bike_id where booking.date != '2011-11-20'
>
>
> On 12/7/11 3:55 PM, Jude Lucien wrote:
>>
>> Sorry for the basic question, I can't seem to figure it out.
>>
>> I have two tables, booking and bike.  Both have bike_id as primary key.
>>
>> I am trying to return all bike_id's where bike.model='Kona' AND
>> booking.booking_date DOES NOT EQUAL 'date';
>>
>> My query is as follows:
>>
>> SELECT bike.bike_id FROM bike,booking WHERE bike.model='model' AND
>> booking.booking_date!='2011-11-20' AND bike.bike_id=booking.bike_id;
>>
>> Any help appreciated!
>>
>> Jude
>>
>>
>>
>
>
> --
> Sent via pgsql-novice mailing list (pgsql-novice(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-novice

--
"None are more hopelessly enslaved than those who falsely believe they
are free"  -- Johann Wolfgang von Goethe

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Ramy Abdel-Azim 2011-12-07 21:16:24 Re: Basic Query Question
Previous Message Ramy Abdel-Azim 2011-12-07 21:02:31 Re: Basic Query Question