Closed Thread
Results 1 to 3 of 3

Thread: SQL on PostgreSQL question linking multiple tables

  1. #1
    Eric The Red is offline Newbie
    Join Date
    Jan 2010
    Location
    Off the left coast of Canada
    Posts
    20
    Rep Power
    0

    SQL on PostgreSQL question linking multiple tables

    Here is what I am trying to do and I am not sure how to do it.

    This is the SQL I am using right now:

    SELECT p.id, p.prop_name, o.id as record_id, o.greeter, o.greet_access, c.id AS greet_id, c.cname, c.fname, c.lname
    FROM prop_info p
    LEFT JOIN owner_info o ON p.id=o.prop_num
    LEFT JOIN contact_list c ON o.greeter=c.id
    WHERE p.book_active=1 AND p.listing_type !=2
    ORDER BY p.prop_name

    so basically pulling a bunch of data from a bunch of different tables that relate to each other but the problem I have is that I need to pull more than 1 set of the c.cname, c.fname, c.lname since there are more than 1 set of numbers in other tables that relate to that information.

    I do not know how to do that, can someone please offer some advice?

    Thanks in advance!

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Posts
    3,082
    Blog Entries
    7
    Rep Power
    42

    Re: SQL on PostgreSQL question linking multiple tables

    join that table again, but name it different, like c1 or g (as in greeter) for this one and make other similar abbreviations for those fields. of course, then match on that other field in the ON part in the join.
    __________________________________________
    I study Information Systems at Karlstad University when I'm not on CodeCall

  4. #3
    Eric The Red is offline Newbie
    Join Date
    Jan 2010
    Location
    Off the left coast of Canada
    Posts
    20
    Rep Power
    0

    Re: SQL on PostgreSQL question linking multiple tables

    A thousand thank yous! That works perfectly! Warm fuzzy feelings :-) I am so happy that I know how to do that now!

    BTW here is the resulting SQL

    SELECT p.id, p.prop_name, o.id as record_id, o.greeter, o.greet_access, c.id AS greet_id, c.cname, c.fname, c.lname, t.id AS sign_up_id, t.fname AS sign_up_fname, t.lname AS sign_up_lname
    FROM prop_info p
    LEFT JOIN owner_info o ON p.id=o.prop_num
    LEFT JOIN contact_list c ON o.greeter=c.id
    LEFT JOIN sign_ups s ON s.prop_num=p.id
    LEFT JOIN contact_list t ON s.sign_up_by=t.id
    WHERE p.book_active=1 AND p.listing_type !=2
    ORDER BY p.prop_name

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Databinding Multiple forms onto same tables
    By Tyrsius in forum C# Programming
    Replies: 4
    Last Post: 05-06-2011, 01:33 PM
  2. Replies: 3
    Last Post: 02-07-2011, 11:29 AM
  3. SVN+Postgresql in Eclipse
    By puuhikki in forum Software Development Tools
    Replies: 0
    Last Post: 09-17-2010, 08:16 AM
  4. C# objects and Postgresql
    By pykie101 in forum C# Programming
    Replies: 2
    Last Post: 06-30-2008, 07:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts