Jump to content


Photo

master & slave table problem


  • Please log in to reply
2 replies to this topic

#1 _confused_

_confused_
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationMeow City

Posted 14 October 2005 - 12:48 AM

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)


#2 _confused_

_confused_
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationMeow City

Posted 14 October 2005 - 01:18 AM

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

#3 _confused_

_confused_
  • Members
  • Pip
  • Newbie
  • 6 posts
  • LocationMeow City

Posted 14 October 2005 - 02:57 AM

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. :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users