Skip site navigation (1) Skip section navigation (2)

Sub_select problem

From: Bernie Huang <bernie(dot)huang(at)ec(dot)gc(dot)ca>
To: PGSQL-SQL <pgsql-sql(at)postgresql(dot)org>, PHP Database <php-db(at)lists(dot)php(dot)net>
Subject: Sub_select problem
Date: 2000-06-27 00:00:15
Message-ID: 3957EE8F.3B145049@ec.gc.ca (view raw or flat)
Thread:
Lists: pgsql-sql
Good day, everyone,

I have 2 tables and 1 datafile as following:

vehicle_tb
-----------
v_id    int4 primary key
display_id    int4
year    text
make    text
model    text
...


vehicle_borrow_log
--------------------
employee_id    int4 (foreign key to emp_tb)
v_id    int4 (foreign key to vehicle_tb)
borrow_time    timestamp
return_time    timestamp
...


datafile.gnu ( a text file)
---------------------------
# Date        Display_id
2000-XX-XX    1
2000-xx-xx    1

2000-XX-XX    2
2000-xx-xx    2

2000-XX-XX    1
2000-xx-xx    1

...


What I want to do is to fetch the display_id in datafile using PHP (by
the way, this part is done).  And then use that display_id to get the
borrow_time and return time in vehicle_borrow_log.  So, I used this
sub-select SQL, but it doesn't seem to be working.

SELECT v_id, borrow_time, return_time
FROM vehicle_borrow_log vbl
WHERE (SELECT equip_id
       FROM vehicle_tb vtb
       WHERE vtb.v_id=vbl.v_id
       AND display_id=$id_from_datafile_let_say_it_is_2);

Could anyone please help?  Thanks!


- Bernie

Attachment: bernie.huang.vcf
Description: text/x-vcard (315 bytes)

pgsql-sql by date

Next:From: K ParkerDate: 2000-06-27 04:52:16
Subject: Re: unique sequences
Previous:From: Gary MacMinnDate: 2000-06-26 23:09:42
Subject: Re: Merging two columns into one

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group