Jump to content

Archived

This topic is now archived and is closed to further replies.

_confused_

master & slave table problem

Recommended Posts

help! how to i reference a record from master table when it doesn't have a child record? below is a sample i got from the postgreSQL manual & my problem is rather similar to that. how should i write my sql query so that CAT will also appear but the vegetable column for it is empty?

 

i've tried using MS Access and the records retrieved is correct. The sql query goes like this:

SELECT animal.animal_id, vegetable.*

FROM animal LEFT JOIN vegetable ON animal.animal_id = vegetable.animal_id;

 

test=> SELECT * FROM animal;
animal_id | name
-----------+-----------------
507 | rabbit
508 | cat
(2 rows)

test=> SELECT * FROM vegetable;
animal_id | name
-----------+-----------------
507 | lettuce
507 | carrot
507 | nut
(3 rows)

test=> SELECT *
test-> FROM animal, vegetable
test-> WHERE animal.animal_id = vegetable.animal_id;
animal_id | name | animal_id | name
-----------+-----------------+-----------+-----------------
507 | rabbit | 507 | lettuce
507 | rabbit | 507 | carrot
507 | rabbit | 507 | nut
(3 rows)

Share this post


Link to post
Share on other sites

i'm running PostgreSQL 7.0.3 and my query using left join gives me this error message. does this mean all hope is gone?? :(

 

PostgreSQL said: ERROR: OUTER JOIN is not yet supported

Share this post


Link to post
Share on other sites

pheww! i've used two sql queries to grab the records separately from both tables and then play around with condition statements...it works perfectly. :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.