Jump to content

master & slave table problem


_confused_

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
https://forums.phpfreaks.com/topic/2660-master-slave-table-problem/
Share on other sites

Archived

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

×
×
  • 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.