Jump to content

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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

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.