X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5F9DDD8F18 for ; Wed, 14 Sep 2005 22:09:56 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03121-04 for ; Thu, 15 Sep 2005 01:09:50 +0000 (GMT) Received: from vms042pub.verizon.net (vms042pub.verizon.net [206.46.252.42]) by svr1.postgresql.org (Postfix) with ESMTP id E19F6D8F8F for ; Wed, 14 Sep 2005 22:09:52 -0300 (ADT) Received: from [192.168.1.13] ([151.200.114.102]) by vms042.mailsrvcs.net (Sun Java System Messaging Server 6.2 HotFix 0.04 (built Dec 24 2004)) with ESMTPA id <0IMU00DJ538JZDC0@vms042.mailsrvcs.net> for pgsql-sql@postgresql.org; Wed, 14 Sep 2005 20:09:56 -0500 (CDT) Date: Wed, 14 Sep 2005 21:11:37 -0400 From: Ferindo Middleton Jr Subject: showing multiple REFERENCE details of id fields in single query that share the same table To: pgsql-sql@postgresql.org Reply-To: fmiddleton@verizon.net Message-id: <4328CA49.7030409@verizon.net> Organization: Sleek Collar MIME-version: 1.0 Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit User-Agent: Thunderbird 1.4 (Windows/20050908) X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=1.458 required=5 tests=[AWL=-0.292, DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376] X-Spam-Level: * X-Archive-Number: 200509/154 X-Sequence-Number: 22701 I have a table which has two id fields which REFERENCE data back at another table. It's setup like this: class_prerequisite_bindings(id SERIAL, class_id INTEGER REFERENCES classes(id), prerequisite INTEGER REFERENCES classes(id)) The classes table is like this: classes(id SERIAL, course_title TEXT, course_code TEXT) I have the following query: SELECT * FROM class_prerequisite_bindings, classes WHERE class_prerequisite_bindings.class_id = 64 AND class_prerequisite_bindings.class_id = classes.id; If I run the query above, the result will only give me info about the class_id field matching id 64 back in the classes table. PROBLEM: I want this query to also show the info about the prerequisite field which would also have info at the classes table. This query will only show the course_title and course_code of the class_id but I need this for the prerequisite field as well. I think I need to do a JOIN, but I don't understand how. How can I do this? Ferindo